PS

BOJ 11645 : I’ve Been Everywhere, Man

lickelon 2025. 2. 11. 21:50
  • 문제 링크 : boj.kr/11645
  • 난이도 : S5
  • 태그 : 문자열, 셋

코드

#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()

#define INF 0x7FFFFFFF

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int T;
    cin >> T;
    while(T--) {
        int n;
        cin >> n;
        set<string> _s;
        for(int i = 0; i < n; i++) {
            string s;
            cin >> s;
            _s.insert(s);
        }
        cout << _s.size() << "\n";
    }

    return 0;
}

풀이

자료구조 set을 이용하면 중복을 제거하고 쉽게 셀 수 있다.

728x90