×

# [closed] bytelandian gold

 0 import java.io.BufferedReader; import java.io.InputStreamReader; class test { public static long coin(long n) { if((coin(n/4)+coin(n/3)+coin(n/2))>n) { return coin(n/4)+coin(n/3)+coin(n/2); } else { return n; } } public static void main(String[] args)throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int lin = 10; while(lin-->0) { long n = Integer.parseInt(br.readLine()); System.out.println(coin(n)); } } }  its giving runtime error !!! asked 09 Jul '13, 09:20 2★zargus 176●6●21●36 accept rate: 0% 1.3k●3●10●25

### The question has been closed for the following reason "The question is answered, right answer was accepted" by sunny_patel 09 Jul '13, 13:48

 2 One obvious mistake i see is the way you have taken the input. Read the statement carefully, The input will contain several test cases (not more than 10). You have directly assumed that number of input will be = 10. But, here in thus problem we need to use EOF(End Of File).EOF is basically a character which indictes end of the file(obviously) and is used when we don't know exact number of test cases. 10 is the upper limit and not the number of cases, there can be files with 1,2,3..10 cases. So, to achieve end of file: Replace in your code:  int lin = 10; while(lin-->0) { long n = Integer.parseInt(br.readLine()); System.out.println(coin(n)); }  With:  String input; while((input=br.readLine())!=null) { long n = Integer.parseInt(input); System.out.println(coin(n)); }  Even after this, I'm not sure taht it will get AC(obviously do try once, good if it does :D ). It might give you RE again. Try to work/optimize your recursive function. :)Hope this helps :) answered 09 Jul '13, 10:24 1.3k●3●10●25 accept rate: 19% 1 yaa needed to use hash table instead got an ac finally :) thnx (09 Jul '13, 13:46) zargus2★

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×545
×231

question asked: 09 Jul '13, 09:20

question was seen: 810 times

last updated: 09 Jul '13, 13:48