在http://www.codechef.com/problems/LASTDIG提交问题时,我不断收到运行时错误。
我的代码如下:
public class Main {
public static void main(String[] args) {
try {
Scanner in = new Scanner(System.in);
int i,j;
System.out.println("Enter the no. of test cases - ");
int cases = in.nextInt();
int[][] a = new int[cases][2];
int[] lds = new int[cases];
for(i=0; i<cases; i++) {
for(j=0; j<2; j++) {
a[i][j]=in.nextInt();
}
}
for(j=0; j<cases; j++) {
lds[j] = 0;
int LENGTH = a[j][1] - a[j][0] +1;
int[] arr = new int[LENGTH];
//System.out.printf("%d\n",LENGTH);
int[]sum = new int[LENGTH];
for(i=0; i<LENGTH; i++) {
sum[i] = 0;
arr[i] = a[j][0] + i;
}
for(i=0; i<LENGTH; i++) {
int temp = arr[i];
while(temp !=0 ) {
int r = temp%10;
temp /= 10;
if (r%2 == 0) sum[i] += r*2;
else sum[i] += r;
}
}
for(i=0; i<LENGTH; i++){
lds[j] += sum[i]%10;
}
}
for(i=0; i<cases; i++) {
System.out.printf("%d\n",lds[i]);
}
}
catch(Exception e) {
e.printStackTrace();
}
}
}
考虑到这个问题很简单,请在这里帮助我。
谢谢 !