12403 - Save Setu

All about problems in Volume 124. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
samikuet
New poster
Posts: 1
Joined: Tue May 26, 2015 9:06 pm

runtime error

Post by samikuet » Tue May 26, 2015 9:15 pm

12403 - Save Setu

I am getting runtime error , but can't find out the reason, i have checked for many inputs and they are ok, but runtime error after submissioin.

code is...

Code: Select all

package setu_main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

 class Main {

	 static void main(String[] args) throws IOException {
		
		BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
		String s=rd.readLine();
		int x=Integer.parseInt(s);
		
		long  res=0;
		for(int i=0;i<x;i++){
			String k=rd.readLine();
			if(k.substring(0,6).matches("report")){
				System.out.println(res);
			}
			else{
			String[] sp=k.split("\\s+");
			long amount=Long.parseLong(sp[1]);
			
			res+=amount;
			
			
			}
		}
		
	}

}
Last edited by brianfry713 on Fri Jun 19, 2015 7:16 am, edited 1 time in total.
Reason: Added code blocks

predicate
New poster
Posts: 18
Joined: Tue Jun 17, 2014 9:32 pm
Location: Hyderabad, India

Re: runtime error

Post by predicate » Sun Jun 07, 2015 7:52 pm

your code fails at the following input:

Code: Select all

4
   donate    1000
    	 report
 donate 500
   report

Post Reply

Return to “Volume 124 (12400-12499)”