我試圖解決我的codechef得到運行時錯誤NZEC問題http://www.codechef.com/APRIL12/problems/DUMPLING/獲取NZEC在Java代碼中
。我在互聯網上搜索,但沒有設法讓我的代碼成功。
這是我的代碼:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class Main {
public BigInteger gcd(BigInteger a,BigInteger b){
if(b.compareTo(BigInteger.valueOf(0)) == 0)
return a;
return gcd(b,a.mod(b));
}
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
int t = 1;
Main obj = new Main();
try{
str = br.readLine();
t = Integer.parseInt(str);
}
catch(IOException e){
System.out.println("error");
}
for(int w = 0; w < t; w++){
BigInteger a = BigInteger.valueOf(1);
BigInteger b = BigInteger.valueOf(1);
BigInteger c = BigInteger.valueOf(1);
BigInteger d = BigInteger.valueOf(1);
BigInteger k = BigInteger.valueOf(1);
try{
str = br.readLine();
String s[] = str.split(" ");
a = new BigInteger(s[0]);
b = new BigInteger(s[1]);
c = new BigInteger(s[2]);
d = new BigInteger(s[3]);
k = new BigInteger(s[4]);
}
catch(IOException e){
System.out.println("error");
}
BigInteger g1,g2,num;
if(a.compareTo(b) < 0){
num = a;
a = b;
b = num;
}
if(c.compareTo(d) < 0){
num = c;
c = d;
d = num;
}
g1 = obj.gcd(a,b);
g2 = obj.gcd(c,d);
if(g1.compareTo(g2) < 0){
num = g1;
g1 = g2;
g2 = num;
}
BigInteger g3 = obj.gcd(g1,g2);
BigInteger l = g1.divide(g3);
l = l.multiply(g2);
BigInteger res = k.divide(l);
BigInteger fin = res.multiply(BigInteger.valueOf(2));
fin = fin.add(BigInteger.valueOf(1));
System.out.println(fin);
}
}
}
誰能請告訴我,我在哪裏做錯了嗎?
我不明白這一行的意思:'我得到運行時錯誤NZEC on codechef'你是否得到一個Java'Exception'?如果是這樣你可以發佈完整的堆棧跟蹤? – ulmangt 2012-04-03 16:35:06
我們應該猜測「NZEC」代表什麼,它出現在哪條線上,輸入的是什麼?如果你不幫助我們幫助你,你真的期望什麼? – 2012-04-03 16:35:25
我在netbeans上運行我的系統上的代碼,它工作正常,但是當我在codechef上提交代碼時,它向我展示了一個運行時錯誤。並且他們不給我們代碼顯示錯誤的行。所以,即使我不爲什麼它顯示運行時錯誤? – 2012-04-03 16:39:24