无法在codechef ide中运行程序。收到CodeChef NZEC错误

时间:2020-01-26 16:29:11

标签: java exception

Problem statement link

因此,此代码在我的系统中可以正常工作,但在Codechef中出现此错误:

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)

代码:

import java.util.Scanner;
import java.lang.*;
import java.io.*;

class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
    Scanner scan = new Scanner(System.in);
    int a,b,c;
    int T = scan.nextInt();
    int arr[] = new int[T];
    for(int i=0;i<T;i++){
        if(scan.hasNextInt()){
         a = scan.nextInt();
         b = scan.nextInt();
         c = scan.nextInt();
        if(a>=1 && b>=1 && c>=1 && a<180 && b<180 && c<180 && a+b+c == 180){
            arr[i]=1;
        }
       }

    }
    for(int i=0;i<T;i++){
        if(arr[i]==1)
        System.out.println("YES");
        else
        System.out.println("NO");
    }
    scan.close();
    }
}

1 个答案:

答案 0 :(得分:1)

这主要是由于尚未提供自定义输入引起的。 InputBuffer实际上是在寻找输入,但是由于您没有明确提供输入,因此会引起问题。

尝试提交后,就可以了。然后,最终裁决取决于您的逻辑和问题的实现。

编辑:我建议使用BufferedReader进行输入,这是令人难以置信的更快。

添加了图像以提供帮助。 Tried compiling use your solution to the Codechef IDE