728x90
반응형
https://www.acmicpc.net/problem/22233
22233번: 가희와 키워드
1번째 글을 쓰고 난 후에, 메모장에 있는 키워드는 set, floyd, os가 됩니다. 2번째 글을 쓰고 난 후에, 메모장에 있는 키워드는 set, os가 됩니다. map은 1번째 글과 2번째 글에 중복으로 등장하였음을
www.acmicpc.net
#include <bits/stdc++.h>
using namespace std;
int N, M;
map<string, int> memo;
vector<string> tokens;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> N >> M;
string input;
for (int i = 0; i < N; i++) {
cin >> input;
memo.insert({input, 0});
}
for (int i = 0; i < M; i++) {
cin >> input;
stringstream sstream(input);
string token;
tokens.clear();
while (getline(sstream, token, ',')) {
tokens.push_back(token);
}
for (int i = 0; i < tokens.size(); i++) {
if (memo.find(tokens[i]) != memo.end()) {
memo.erase(tokens[i]);
}
}
cout << memo.size() << "\n";
}
}
hash를 써서 해결했습니다.
어려운 문제는 아닌데 문자열 함수들이 기억이 안나서 검색하면서 했습니다.
728x90
반응형
'Algorithm > C++' 카테고리의 다른 글
| [C++] 20006 : 랭킹전 대기열 (0) | 2024.04.24 |
|---|---|
| [C++] 19637 : IF문 좀 대신 써줘 (0) | 2024.04.02 |
| [C++] 20310 : 타노스 (0) | 2024.03.28 |
| [C++] 3758 : KCPC (0) | 2024.03.28 |
| [C++] 19941 : 햄버거 분배 (0) | 2024.03.11 |