我在解决杭电Acm的A1002时,编写的程序总是出现wrong answer,希望大家帮忙解决下,谢谢~~~

2024-11-15 15:40:10
推荐回答(1个)
回答1:

mport java.util.Scanner;

public class A1002 {

public static void main(String[] args) {
int start=0;
int start1=0;
int temp1=0;
int temp2=1;
Scanner sc=new Scanner(System.in);
int geShu=sc.nextInt();
long shu[]=new long[geShu*2];
if(geShu>=1&&geShu<=20){//你这样写是不对的,因为数灶模字太大啦,你的long根本隐厅缓就存不下,你不信试1000000000000000000000000000000000000000 22222222222222222222222222222222222222222222222222222222
//这个数据,其JAVA里面有一个大数类,专门用来计算这些大伏腊数的,你可以学习一下.
//BigInteger类
while(start<(geShu*2)){//总共输入几个数
shu[start]=sc.nextLong();
start++;
}
//计算并输入结果
while (start1 System.out.println("Case "+(start1+1)+":");

System.out.println(shu[temp1]+" + "+shu[temp2]+" = "+(shu[temp1]+shu[temp2]));
System.out.println();

start1+=1;
temp1+=2;
temp2+=2;
}
}
}

}