안녕하세요. 오늘은 중요한 메시지를 확인할 거예요.

문제

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

아이디어

어떤 이메일이 연락처에 있는지를 map에 저장합시다. 그리고 나중에 map에서 find를 해주면 됩니다.

소스코드

#include <iostream>
#include <string>
#include <map>
#define ll long long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll N, M, i, cnt = 0;
    string s;
    map <string, bool> mp;

    cin >> N;
    for (i = 1; i <= N; i++)
    {
        cin >> s;
        mp[s] = true;
    }
    cin >> M;
    for (i = 0; i < M; i++)
    {
        cin >> s;
        if (mp.find(s) != mp.end()) cnt++;
    }
    cout << cnt;
}


감사합니다.

0개의 댓글