반응형
문제 출처 :
https://www.acmicpc.net/problem/14425
알고리즘 분석 :
문제 해결에 필요한 사항
1. Map STL :: http://programbasic.tistory.com/604
Map을 이용하여 해결 할 수 있는 간단한 문제이다.
첫 n개의 값을 map에 집어넣고 그다음 m개의 값이 map에 존재한다면 +1씩 해주어 정답을 도출하면 된다.
소스 코드 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <iostream> #include <cstdio> #include <map> #include <string> using namespace std; int main() { int n, m; scanf("%d %d", &n, &m); map<string, bool> mp; for (int i = 0; i < n; i++) { string str; cin >> str; mp[str] = true; } int cnt = 0; for (int i = 0; i < m; i++) { string str; cin >> str; if (mp[str]) cnt++; } cout << cnt; return 0; } // This source code Copyright belongs to Crocus // If you want to see more? click here >> | Crocus |
반응형
'Applied > 알고리즘 문제풀이' 카테고리의 다른 글
[4246번] To and Fro (0) | 2017.09.08 |
---|---|
[5214번] 환승 (2) | 2017.09.03 |
[1535번] 안녕 (0) | 2017.08.24 |
[2585번] 경비행기 (8) | 2017.08.24 |
[2517번] 달리기 (2) | 2017.08.24 |