• 문제 링크
https://www.acmicpc.net/problem/20732
• 풀이 코드
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;
import java.util.StringTokenizer;
public class Main {
static Set<String> 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));
String res = "correct";
int n = Integer.parseInt(br.readLine());
for (int t = 1; t <= n; t++) {
String s = br.readLine();
int i = s.indexOf("-");
if (i == 0) set.add(s.substring(3));
else if (contains(s.substring(0, i - 1))) set.add(s.substring(i + 3));
else {
res = String.valueOf(t);
break;
}
}
bw.write(res);
bw.flush();
}
private static boolean contains(String s) {
StringTokenizer st = new StringTokenizer(s);
while (st.hasMoreTokens()) if (!set.contains(st.nextToken())) return false;
return true;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 33664 현실적인 생일 축하 방안 - Data Structure / Java (0) | 2025.04.04 |
---|---|
[백준] 11419 Olympic Parade - Data Structure / Java (0) | 2025.04.03 |
[백준] 20125 쿠키의 신체 측정 - Implementation / Java (0) | 2025.04.01 |
[백준] 1531 투명 - Implementation / Java (0) | 2025.03.31 |
[백준] 5704 팬그램 - Implementation / Java (0) | 2025.03.30 |
댓글