开发者

Runtime Error (NZEC) in simple code

I'm getting runtime error (NZEC) when running the following code over at SPOJ. I'd be very thankful if any of you would kindly point out what's going on.

//0<=A<=B<=10^18, 1<=N<=10^18
using System;
class any
{
static void Main()
 {
    long t = long.Parse(Console.ReadLine());
    ulong a, b, n;

    for(long k = 0; k &开发者_StackOverflow社区lt; t; k++)
     {
        string[]s = Console.ReadLine().Split(' ');
        a = ulong.Parse(s[0]);
        b = ulong.Parse(s[1]);
        n = ulong.Parse(s[2]);
        Console.WriteLine(diviEntre2(a, b, n));
     }
 }
static ulong diviEntre2(ulong f, ulong c, ulong n)
{
   ulong k, s, m;

    if (f == c && c % n == 0 && f != 0) k = c/n;

    else
     {
      s = f/n;
      m = c/n;

      k = m - s;
     }

  return k;
}
}


NZEC stands for Non Zero Exit Code. For C users, this will be generated if your main method does not have a return 0; statement. Other languages like Java/C++ could generate this error if they throw an exception.


For Java, NZEC is returned when the code throws an exception. For problems on Spoj, etc often the last line in the input causes this exception if the test cases are not terminated by an identifier string.

For such cases, a useful hack is to wrap your code in a try - catch and simply return if there's an exception. The caught exception signals that you've reached the end of input.

public static void main(String[] args) {
    temp program = new temp();
    try{
    program.begin();
    } catch(Exception e){
        return;
    }
}


I had the same message while programming in java. It turned out I should have put my source code in default package (or not change package at all). I hope this helps someone.


I don't know what java returns when the main function is void, but this can be the reason of this error message. Spoj also checks the return value of your program, and it expects 0 (success/non-error code). I guess changing your main function to return 0 will fix this error message.

I just had this same error with a C program, and adding a return 0 changed the error to accepted.


This error can also mean that the program does not work correctly that is the output is not the expected output... believe it or not this is a strong possibility that your code is just not doing what the question asks it to....

Quoting from the link given at the end ->

NZEC (non-zero exit code) - helps telling crash from WA with interpreted languages; WA = Wrong Answer.

please see this link The SPOJ System


I got NZEC on a cpp program for the problem 'EKO'. I was making an array declaration right before the int main() statement. I shifted the declaration inside the main function and the solution got accepted.

I normally have the array declaration outside the main function but in this case the array was a big one (int array[100001]). So may be declare your arrays inside main.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜