Runtime Error (NZEC) in simple code

旧巷老猫 提交于 2019-12-17 16:48:07

问题


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 < 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;
}
}

回答1:


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.




回答2:


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;
    }
}



回答3:


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.




回答4:


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.




回答5:


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




回答6:


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.



来源:https://stackoverflow.com/questions/5436207/runtime-error-nzec-in-simple-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!