NZEC error PLMU

/* package codechef; // don’t place package name! */

import java.lang.;
import java.io.
;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws IOException
{
// your code goes here
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int testCase,i,j,noOfElement,k1=0,k2=0,inp,ans;
testCase=Integer.parseInt(in.readLine());
for(i=0;i<testCase;i++)
{
k1=0;
k2=0;
ans=0;
noOfElement=Integer.parseInt(in.readLine());
for(j=0;j<noOfElement;j++)
{
inp=Integer.parseInt(in.readLine());
if(inp==2)
{
k1++;
}
if(inp==0)
{
k2++;
}
}

       ans=(int)(0.5*(k1*(k1-1)+k2*(k2-1)));
       System.out.println(ans);
	}
}

}

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

This solution caused no errors.
https://www.codechef.com/viewsolution/28381420

Link to source code
https://www.codechef.com/viewsolution/28390478

1 Like

I have encountered similar errors for many solutions.
Can someone please help me deal with this problem?
Both scanner and buffered reader have caused similar errors for me before.

This fails on the sample testcase:

>echo "2
3
2 4 2
3
0 2 3

" | ./run-java.sh
Exception in thread "main" java.lang.NumberFormatException: For input string: "2 4 2"
        at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.base/java.lang.Integer.parseInt(Integer.java:652)
        at java.base/java.lang.Integer.parseInt(Integer.java:770)
        at Codechef.main(kishan_pi-PLMU.java:24)

The N elements for a testcase all occur on one line, not on N different lines :slight_smile:

2 Likes

@ssjgz How can I deal with it?
How did you detect this error?

Learn how to read input in Java - the other AC solutions will help you :slight_smile: Here’s one I’ve picked at random.

I just ran your code with the given sample testcase on my local machine.

1 Like

Thanks for the help

1 Like