• 문제 링크
https://www.acmicpc.net/problem/1331
• 풀이 코드
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 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Set<String> set = new HashSet<>();
String s = br.readLine(), a = s, b;
set.add(a);
for (int i = 0; i < 35; i++, a = b) if (!isValid(a, b = br.readLine()) || !set.add(b)) break;
bw.write(set.size() == 36 && isValid(s, a) ? "Valid" : "Invalid");
bw.flush();
}
private static boolean isValid(String a, String b) {
return Math.abs(a.charAt(0) - b.charAt(0)) * Math.abs(a.charAt(1) - b.charAt(1)) == 2;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 10409 서버 - Implementation / Java (0) | 2025.06.18 |
---|---|
[백준] 12871 무한 문자열 - Implementation / Java (0) | 2025.06.17 |
[백준] 11575 Affine Cipher - Implementation / Java (0) | 2025.06.15 |
[백준] 13416 주식 투자 - Implementation / Java (0) | 2025.06.14 |
[백준] 3059 등장하지 않는 문자의 합 - Implementation / Java (0) | 2025.06.13 |
댓글