https://www.acmicpc.net/problem/14425
<์์ฝ>
์ด N๊ฐ์ ๋ฌธ์์ด๋ก ์ด๋ฃจ์ด์ง ์งํฉ S๊ฐ ์ฃผ์ด์ง๋ค.
์ ๋ ฅ์ผ๋ก ์ฃผ์ด์ง๋ M๊ฐ์ ๋ฌธ์์ด ์ค์์ ์งํฉ S์ ํฌํจ๋์ด ์๋ ๊ฒ์ด ์ด ๋ช ๊ฐ์ธ์ง ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
algorithm ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ include ํด์ค์ผ ํจ
์ง์ ์ฝ๋๋ก ๊ตฌํํ์ง ์๊ณ ๋ binary search ํ์ ๊ฐ๋ฅ
binary_search(์์์ , ๋์ , ๋น๊ต๊ฐ)์ผ๋ก ์ ์ธํ๊ณ ๋ฐํํ์ boolํ
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m, cnt=0;
cin >> n >> m;
vector <string> word;
string str;
for (int i = 0; i < n; i++) {
cin >> str;
word.push_back(str);
}
sort(word.begin(), word.end());
for (int i = 0; i < m; i++) {
cin >> str;
if (binary_search(word.begin(), word.end(), str)) cnt++;
}
cout << cnt;
return 0;
}
์ฝ๋ ์ ์ถํ๊ณ ๋จ๋ค์ ์ด๋ป๊ฒ ํ๋ ๋ณด๋ค๊ฐ unordered_map์ด๋ผ๋ ๊ฒ์ ๋ฐ๊ฒฌํ๋ค. ๊ณง ์ ๋ฆฌํด์ ์ฌ๋ ค๋ด์ผ์ง