|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
题目如下:
https://www.lanqiao.cn/problems/1025/learning/
代码如下:
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int res = 0;
int temp = 0;
int n = scanner.nextInt();
int[][] a = new int[n+1][5];
for (int i = 1; i < n+1; i++) {
a[i][0] = scanner.nextInt();
a[i][1] = scanner.nextInt();
a[i][2] = scanner.nextInt();
a[i][3] = a[i][0] + a[i][1] + a[i][2];
a[i][4] = a[i][0] + a[i][1];
}
//冒泡排序
for (int j = 0; j < n; j++) {
for (int k = 0; k < n-j; k++) {
if (a[k][3]>a[k+1][3]) {
jiaohuan(a[k],a[k+1]);
}
else if (a[k][3]==a[k+1][3]&&a[k][4]>a[k+1][4]) {
jiaohuan(a[k],a[k+1]);
}
}
}
// for (int i = 0; i < a.length; i++) {
// for (int j = 0; j < a[i].length; j++) {
// System.out.print(a[i][j]+" ");
// }
// System.out.println();
// }
for (int i = 1; i < n+1; i++) {
temp += a[i-1][0] + a[i-1][1] + a[i-1][2] + a[i][0] + a[i][1] - a[i-1][0] - a[i-1][1];
res += temp;
}
System.out.print(res);
}
public static void jiaohuan(int[] x,int[] y) {
int temp = 0;
for (int i = 0; i < 5; i++) {
temp = x[i];
x[i] = y[i];
y[i] = temp;
}
}
}
题目提供的例子可以通过,但是其他就不行了,请问是哪里错了呢??? |
|