-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14425_문자열집합.cpp
72 lines (58 loc) · 1.01 KB
/
14425_문자열집합.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
vector<string>stringS;
vector<string>stringM;
int N, M;
int cnt = 0;
int compareString(string a, string b) {
if (a == b) {
return 0;
}
else if (a > b) {
return 1;
}
else {
return -1;
}
return 3;
}
int main() {
cin >> N >> M;
string temp;
for (int i = 0; i < N; i++) {
cin >> temp;
stringS.push_back(temp);
}
sort(stringS.begin(), stringS.end());
for (int i = 0; i < M; i++) {
cin >> temp;
stringM.push_back(temp);
}
sort(stringM.begin(), stringM.end());
for (int i = 0; i < M; i++) {
int start = 0;
int end = stringS.size() - 1;
while (start <= end ) {
int mid = (start + end) / 2 ;
int seperator = compareString(stringM[i], stringS[mid]);
if (seperator == 0) {
cnt++;
break;
}
else if (seperator == -1) {
end = mid - 1;
}
else if(seperator==1){
start = mid + 1;
}
}
}
cout << cnt;
return 0;
}