알고리즘/백준

백준 11645 I’ve Been Everywhere, Man

등반 2021. 12. 27. 01:26

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

 

11645번: I’ve Been Everywhere, Man

The first line of input contains a single positive integer T ≤ 50 indicating the number of test cases. The first line of each test case also contains a single positive integer n indicating the number of work trips Alice has taken so far. The following n

www.acmicpc.net

문제 해설

주인공이 다녀온 모든 도시의 개수를 출력하는 문제다.(중복 없이)

 

이런 문제는 map[sth]++ 를 이용해 쉽게 해결할 수 있다.

해당 값이 없는 경우 map[sth]까지 입력될 때, map[sth] = 0까지 입력이 되고,

이후 "++"가 계산되어 map[sth] = 1;이 된다.

값이 존재하는 경우엔 "++"만 계산된다.

#include <iostream>
#define fio cin.tie(0)->sync_with_stdio(0)
using namespace std;

#include <set>
int main(){
    fio;
    int T; cin >> T;
    for(int t = 1; t<= T; t++){
        int N; cin >> N;
        set<string> set_;
        for(int i=0; i <N; i++){
            string S; cin >> S;
            set_.insert(S);
        }
        cout << set_.size() <<'\n';
    }
    return 0;
}