- ๋ฌธ์
์ด N๊ฐ์ ๋ฌธ์์ด๋ก ์ด๋ฃจ์ด์ง ์งํฉ S๊ฐ ์ฃผ์ด์ง๋ค.
์ ๋ ฅ์ผ๋ก ์ฃผ์ด์ง๋ M๊ฐ์ ๋ฌธ์์ด ์ค์์ ์งํฉ S์ ํฌํจ๋์ด ์๋ ๊ฒ์ด ์ด ๋ช ๊ฐ์ธ์ง ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
- Code
#include <iostream>
#include <set>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m, ans = 0;
string input;
set<string> s;
//์
๋ ฅ
cin >> n >> m;
while (n--) {
cin >> input;
s.insert(input);
}
//์ฐ์ฐ
while (m--) {
cin >> input;
if (s.find(input) != s.end()) { // ๊ฐ์๊ฒ ์์ผ๋ฉด ans +1
ans++;
}
}
//์ถ๋ ฅ
cout << ans;
return 0;
}
- ํด์ค
1. ์
์ถ๋ ฅ ํจ์์ ์๋๋ฅผ ๋์ด๋ ์ฝ๋๋ฅผ ์ ์
2. ์งํฉ s์ ๋ฌธ์์ด์ ๊ฐ์, ์
๋ ฅ๋ ๋ฌธ์์ด์ ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ์
3. input์ n๊ฐ ๋งํผ ๋ค์ด์ค๋ ๋ฌธ์์ด์ ์
๋ ฅ๋ฐ์ ์งํฉ s์ insert ํจ
4. m๋ฒ ๋ฐ๋ณตํ๋ฉฐ ์
๋ ฅ๋๋ ๋ฌธ์์ด์ input์ ๋์
ํ๊ณ find ํจ์๋ฅผ ์ด์ฉํด ์งํฉ s์์ ๊ฐ์ ๋ฌธ์์ด์ด ์์ผ๋ฉด ans๋ฅผ ์ฆ๊ฐํจ
5. ans ์ถ๋ ฅ