Java小白感觉自己写的很麻烦,求大佬简化一下orz orz orz orz orz 代码如下:
import java.util.Scanner;
public class P5594 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int members, totalDays, haveDays;
members = scanner.nextInt();
haveDays = scanner.nextInt();
totalDays = scanner.nextInt();
//使用二维数组,第一维长度为总天数,第二位为成员数量
boolean[] hasMatch = new boolean[totalDays];
int[][] matches = new int[totalDays][members];
//根据成员数建立循环,将二维数组第一维改为1如果当天有模拟赛,第二位填入所需卷子
for (int i = 0; i < members; i++) {
int paperNum = 1;
for(int j = 0; j < haveDays; j++) {
int day = scanner.nextInt() - 1;
matches[day][i] = paperNum;
hasMatch[day] = true;
paperNum++;
}
}
//遍历数组,将卷子数相加,如果有相同的卷子算作一场,输出结果
int i = 0;
for(boolean bol : hasMatch) {
int count = 0;
boolean[] papers = new boolean[haveDays+1];
if (!bol) {
System.out.print(0+" ");
} else {
for (int j = 0; j < members; j++) {
int paperNum = matches[i][j];
if (!papers[paperNum] && paperNum != 0) {
papers[paperNum] = true;
count++;
}
}
System.out.print(count + " ");
}
i++;
}
scanner.close();
}
}