• 문제 링크
https://www.acmicpc.net/problem/1268
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
static int[][] mat;
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read();
mat = new int[n][5];
for (int i = 0; i < n; i++) for (int j = 0; j < 5; j++) mat[i][j] = read();
int max = 0, res = 0;
for (int i = 0; i < n; i++) {
int[] arr = new int[5];
System.arraycopy(mat[i], 0, arr, 0, 5);
int cnt = 0;
for (int j = 0; j < n; j++) if (j != i && search(arr, j)) cnt++;
if (max < cnt) {
max = cnt;
res = i;
}
}
bw.write(String.valueOf(res + 1));
bw.flush();
}
private static boolean search(int[] arr, int j) {
for (int k = 0; k < 5; k++) if (arr[k] == mat[j][k]) return true;
return false;
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 1864 문어 숫자 - Implementation / Java (0) | 2025.04.24 |
---|---|
[백준] 3613 Java vs C++ - Implementation / Java (0) | 2025.04.23 |
[백준] 5533 유니크 - Implementation / Java (0) | 2025.04.21 |
[백준] 4493 가위 바위 보? - Implementation / Java (0) | 2025.04.20 |
[백준] 24081 箱と鍵 (Boxes and Keys) - Brute Force / Java (0) | 2025.04.19 |
댓글