AcWing 1540. 主导颜色-java
原题链接
简单
作者:
Astarion
,
2021-03-08 17:37:09
,
所有人可见
,
阅读 346
import java.io.*;
class Main {
static int[] cnt = new int[20000000];
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(isr);
OutputStreamWriter osw = new OutputStreamWriter(System.out);
BufferedWriter out = new BufferedWriter(osw);
String[] strs = in.readLine().split(" ");
int m = Integer.parseInt(strs[0]);
int n = Integer.parseInt(strs[1]);
int maxN = 0; int id = 0;
for (int i = 0; i < n; i++) {
strs = in.readLine().split(" ");
for (int j = 0; j < m; j++) {
int color = Integer.parseInt(strs[j]);
cnt[color]++;
if (cnt[color] > maxN) {
id = color;
maxN = cnt[color];
}
}
}
out.write(id+"");
in.close();
isr.close();
out.flush();
out.close();
osw.close();
}
}