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;
}
'알고리즘 > 백준' 카테고리의 다른 글
백준 12015 가장 긴 증가하는 부분 수열 2 +a (0) | 2021.12.28 |
---|---|
백준 12034 김인천씨의 식료품가게 (Large) (0) | 2021.12.27 |
백준 11507 카드셋트 (0) | 2021.12.27 |
백준 11346 Cornell Party - Retry (0) | 2021.12.27 |
백준 11235 Polling (0) | 2021.12.27 |