2016-03-21 34 views
-2

我最近在竞争性编程中从C转移到了Java。但是我提交的任何解决方案都会显示NZEC运行时错误。一个这样的问题是https://www.codechef.com/problems/FCTRL2 和我的解决办法是为什么这段代码不工作? FCTRL2

import java.util.Scanner; 
import java.math.BigInteger; 

class Solution{ 
    public int t, i=0; 
    public BigInteger N; 
    public static void main(String args[]){ 
     Solution sol = new Solution(); 
     sol.scanT(); 
     sol.testCase(); 
     System.exit(0); 
    } 

    public void scanT(){ 
     Scanner sc = new Scanner(System.in); 
     t = sc.nextInt(); 
     if(t>100 || t<1){ 
      return; 
     } 
    } 

    public void testCase(){ 
     Scanner sc = new Scanner(System.in); 
     for(i=0; i<t; i++){ 
      N = sc.nextBigInteger(); 
      if(N.compareTo(BigInteger.ONE)<0 || N.compareTo(BigInteger.valueOf(100))>0){ 
       return; 
      } 
      BigInteger z = factorial(); 
      System.out.println(z); 
     } 

    } 

    public BigInteger factorial(){ 
     BigInteger Fact = N; 
     while(N.compareTo(BigInteger.valueOf(2))>0){ 
      Fact = Fact.multiply(N.subtract(BigInteger.ONE)); 
      N = N.subtract(BigInteger.ONE); 
     } 
    return Fact; 
    } 
} 

请帮我找到我的解决方案的错误,导致运行错误NZEC每次。我的解决方案在计算机上运行时显示正确的输出。

+1

寻求调试帮助的问题(“为什么这个代码不工作?”)必须包含所需的行为,特定的问题或错误以及在问题本身中重现问题所需的最短代码。没有明确问题陈述的问题对其他读者无益。请参阅:[如何创建一个最小,完整和可验证的示例。](http://stackoverflow.com/help/mcve) – user7

+0

不确定问题是什么,但为什么要创建多个扫描程序? – Ramanlfc

+0

尝试创建只有一个扫描仪 – user7

回答

1

NZEC错误是由于同时使用System.in的多个Scanner对象而生成的。 仅使用一个扫描仪对象可解决运行时错误NZEC的问题。