본문 바로가기
Problem Solving/Baekjoon

[백준] 11645 I’ve Been Everywhere, Man - Data Structure / Java

by graycode 2025. 2. 8.

 문제 링크

https://www.acmicpc.net/problem/11645

 

 풀이 코드

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));
        StringBuilder sb = new StringBuilder();

        Set<String> set = new HashSet<>();
        int t = Integer.parseInt(br.readLine());
        while (t-- > 0) {
            int n = Integer.parseInt(br.readLine());
            while (n-- > 0) set.add(br.readLine());
            sb.append(set.size()).append("\n");
            set.clear();
        }

        bw.write(sb.toString());
        bw.flush();
    }

}

댓글