반응형

문제 출처 :


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



알고리즘 분석 :


문제 해결에 필요한 사항

1. Map STL


문제를 다음과 같이 해결한다.


n을 입력받고 n개의 줄에서 입력을 받는다. 이때 map에 저장을 하여 각 단어가 몇번 나온지 체크한다.


그 후 n개의 줄에서 입력을 받는데 각 단어가 몇번 나온지 존재한다면 몇번 일치하는지 계산을 해주고 결과를 구한다.







소스 코드 : 


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
39
40
41
#include <iostream>
#include <cstdio>
#include <map>
#include <string>
 
using namespace std;
 
map<string, int> mp;
 
int main()
{
    int n;
    cin >> n;
 
    for (int i = 0; i < n; i++)
    {
        string str;
        cin >> str;
 
        mp[str]++;
    }
 
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        string str;
        cin >> str;
 
        if (mp[str])
        {
            ans++;
            mp[str]--;
        }
    }
 
    printf("%d", ans);
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus


반응형

'Applied > 알고리즘 문제풀이' 카테고리의 다른 글

[1947번] 선물 전달  (0) 2017.12.18
[1236번] 성 지키기  (0) 2017.12.17
[2401번] 문자열 붙여넣기  (0) 2017.12.12
[1893번] 시저 암호  (0) 2017.12.11
[11585번] 속타는 저녁 메뉴  (0) 2017.12.11