您的位置:首页 > 编程语言 > Java开发

杭电 2023 ( 求平均成绩 ) java

2017-01-24 16:43 225 查看
import java.util.*;

public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
int m = sc.nextInt();
double ave = 0;
double ave2 = 0;
int count = 0;
int count2 = 0;
int t = 0;
double save[] = new double[m];
double save1[] = new double
;
int arr[][] = new int[50][5];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = sc.nextInt();
}
}

for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ave += arr[i][j];
count++;
if (count == m) {
save1[i] = ave / m;
if (i == 0) {
System.out.printf("%.2f", save1[i]);
} else {
System.out.printf(" " + "%.2f", save1[i]);
}
ave = 0;
count = 0;
}
}
}
System.out.println();

for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
ave2 += arr[j][i];
count2++;
if (count2 == n) {
save[i] = ave2 / n;
if (i == 0) {
System.out.printf("%.2f", save[i]);
} else {
System.out.printf(" " + "%.2f", save[i]);
}

ave2 = 0;
count2 = 0;
}
}
}

System.out.println();

int count3 = 0;
int q = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {

if (arr[i][j] >= save[j]) {
count3++;
}
}

if (count3 == m) {
q++;
}
count3 = 0;
}
System.out.println(q);
System.out.println("");

}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息