• 문제 링크
https://www.acmicpc.net/problem/32371
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashSet;
import java.util.Set;
public class Main {
static char[][] mat = new char[4][10];
static Set<Character> set = new HashSet<>();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
for (int i = 0, j = 0; i < 4; i++, j = 0) for (char c : br.readLine().toCharArray()) mat[i][j++] = c;
for (char c : br.readLine().toCharArray()) set.add(c);
bw.write(String.valueOf(search()));
bw.flush();
}
private static char search() {
for (int i = 1; i < 3; i++) for (int j = 1; j < 9; j++) if (compare(i, j)) return mat[i][j];
return ' ';
}
private static boolean compare(int i, int j) {
return set.contains(mat[i][j]) && set.contains(mat[i - 1][j]) && set.contains(mat[i - 1][j + 1]) && set.contains(mat[i][j + 1]) && set.contains(mat[i + 1][j + 1]) && set.contains(mat[i + 1][j]) && set.contains(mat[i + 1][j - 1]) && set.contains(mat[i][j - 1]) && set.contains(mat[i - 1][j - 1]);
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 5576 콘테스트 - Implementation / Java (0) | 2024.12.07 |
---|---|
[백준] 1236 성 지키기 - Implementation / Java (0) | 2024.12.06 |
[백준] 15449 Art - Brute Force / Java (0) | 2024.12.04 |
[백준] 11680 Dice Cup - Brute Force / Java (0) | 2024.12.03 |
[백준] 19751 Fractification - Brute Force / Java (0) | 2024.12.02 |
댓글