1일1알

백준 22233번 가희와 키워드 C++ 본문

알고리즘

백준 22233번 가희와 키워드 C++

영춘권의달인 2023. 3. 3. 12:14

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

 

22233번: 가희와 키워드

1번째 글을 쓰고 난 후에, 메모장에 있는 키워드는 set, floyd, os가 됩니다. 2번째 글을 쓰고 난 후에, 메모장에 있는 키워드는 set, os가 됩니다. map은 1번째 글과 2번째 글에 중복으로 등장하였음을

www.acmicpc.net

 

set으로 하면 안되고 unordered_set으로 하면 통과된다.

 

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>

using namespace std;
using int64 = long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m;
    cin >> n >> m;
    unordered_set<string> s;
    for (int i = 0; i < n; i++) {
        string str;
        cin >> str;
        s.insert(str);
    }
    for (int i = 0; i < m; i++) {
        string str;
        cin >> str;
        string tmp = "";
        int front = 0;
        for (int j = 0; j <= str.length(); j++) {
            if (j != str.length() && str[j] != ',') continue;
            tmp = str.substr(front, j - front);
            front = j + 1;
            s.erase(tmp);
        }
        cout << s.size() << "\n";
    }
}