Runtime Error (NZEC) in simple code

前端 未结 6 1130
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 05:41

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.

         


        
相关标签:
6条回答
  • 2020-12-11 06:16

    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.

    0 讨论(0)
  • 2020-12-11 06:20

    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;
        }
    }
    
    0 讨论(0)
  • 2020-12-11 06:20

    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

    0 讨论(0)
  • 2020-12-11 06:24

    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 讨论(0)
  • 2020-12-11 06:30

    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.

    0 讨论(0)
  • 2020-12-11 06:31

    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.

    0 讨论(0)
提交回复
热议问题