• 문제 링크
https://www.acmicpc.net/problem/26069
• 풀이 코드
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 {
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<>();
set.add("ChongChong");
int n = Integer.parseInt(br.readLine());
while (n-- > 0) {
StringTokenizer st = new StringTokenizer(br.readLine());
String a = st.nextToken(), b = st.nextToken();
if (!set.contains(a) && !set.contains(b)) continue;
set.add(a);
set.add(b);
}
bw.write(String.valueOf(set.size()));
bw.flush();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 30018 타슈 - Greedy / Java (0) | 2025.04.08 |
---|---|
[백준] 4466 A Smart Brain is a Tasty Brain - Data Structure / Java (0) | 2025.04.07 |
[백준] 25192 인사성 밝은 곰곰이 - Data Structure / Java (0) | 2025.04.06 |
[백준] 33664 현실적인 생일 축하 방안 - Data Structure / Java (0) | 2025.04.04 |
[백준] 11419 Olympic Parade - Data Structure / Java (0) | 2025.04.03 |
댓글