Page 1 of 1

runtime error

Posted: Tue May 26, 2015 9:15 pm
by samikuet
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;
			
			
			}
		}
		
	}

}

Re: runtime error

Posted: Sun Jun 07, 2015 7:52 pm
by predicate
your code fails at the following input:

Code: Select all

4
   donate    1000
    	 report
 donate 500
   report