NZEC means “Non zero exit code”. Its essentially saying that your program ran into some error during execution. Mostly, it comes up when there is a Segmentation Fault.
The SegFault can be caused by many things, but experience says it is mainly through two causes:
(a) Infinite Recursion - or basically when you run out of stack memory.
(b) Incorrect Memory Access -
or whenever there is some weird stuff happening with memory allocation / access. C++ isn’t so friendly as Java, and it will not explicitly tell you that you have an “ArrayIndexOutOfBounds Exception”, but will instead try to use the “supposed” memory even if it is outside the block. This makes things a bit hard to debug.
If you’re accessing things far out for example.
Some sample codes that should give NZEC on Codechef/Spoj:
Example 1: DFS
void dfs(int u)
{
visited[u]++;
for(int v = 0; v < N; v++)
if(adjmat[u][v] == 1)
dfs(v);
}
If you are submitting the code by copying from your IDE, make sure you select the code from import statements not from your package statement.
This will also give you NZEC error. Please check your submission.
@throws java.lang.Exception
*/
public static void main(String[] args) throws Exception
{
// TODO code application logic here
int n;
int i,j,k,l;
System.out.println(“enter the test cases”);
String str;
BufferedReader b = new BufferedReader (new InputStreamReader(System.in));
str=b.readLine();
n=Integer.parseInt(str);
// for (i=0;i<n;i++)
// {
while (n>0)
{
str=b.readLine();
i=Integer.parseInt(str);
str=b.readLine();
j=Integer.parseInt(str);
str=b.readLine();
k=Integer.parseInt(str);
str=b.readLine();
l=Integer.parseInt(str);
Alright I don’t seem to have a high enough Karma or something to ask a separate question so I thought I’d post it here since the topic is related.
I keep getting an NZEC error at the spot I marked by a comment in my code when running it on the online IDE set to the problem CHEFCHR (I’m aware the contest is still going on which is why I omitted specific code to prevent illegal use):
/* package codechef; // don't place package name! */
import java.util.*;
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 java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int cases = sc.nextInt(); //THE NZEC ERROR IS HAPPENING HERE
for(int i = 0;i < cases;i++)
{
String s = sc.next();
/* Omitted code for sake of confidentiality since the contest is still running */
}
}
}
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Codechef.main(Main.java:14)
When I run this code in my ide (NetBeans), I’m fine and everything works perfectly. When I run it on the online IDE with custom input, everything is fine as well. When I run it with the CHEFCHR input, I’m given an NZEC error. When I’ve been submitting, it’s been telling me my code gives the wrong answer.
Even if I run LITERALLY ONLY the code below, I get the same exact NZEC error:
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int cases = sc.nextInt();
}
}
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Codechef.main(Main.java:11)
What am I doing wrong if even just calling for scanner to read in an integer is giving me an error?
Both programs are EXACTLY the same. No alterations. Both are answering the same question. Yet one is right and one is wrong. Plz help, I’m losing my marbles.
I am facing the same problem. I have used Scanner class for input and i am getting the error in the exact same line. I have tried the try-catch block. The NZEC problem still persists. Please help.
NZEC might occur because sometimes your code must not be getting passed for all possible types of Test Cases. Please understand the problem statement and try to run your code with various scenarios. There is a possibility that the code might be failing for a particular Test case.
It has happened with me, as well. I found out that my code wasn’t working for a particular TC. I changed my code logic accordingly and NZEC error did’t occur.
Codechef accepted my solution.
So please design your code that handles as many varieties of Test cases as possible.
but if it throws an exception then it will not execute the code…then u’ll get a WA…it is better if u check if your input format is correct…i.e while using bufferedReader and specially while using the readLine() function…also u should take care array out of bounds excep…the above format will only help to find where the error is occurring and that to only if u have the specific cases…as the example cases or many small cases may pass…
NO actually you see, it’s not like that! That’s the convention how you write it at the beginning at the function. It’s a built-in exception class. The way I coded is similar to something like below and both means the same, just different convention or writing practice-
One thing I’ve noticed is using string tokenizer to parse input is always better than using split function. The latter many times lead to IOException/NZEC.