-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path363. New Cell Phone.cpp
67 lines (48 loc) · 1.23 KB
/
363. New Cell Phone.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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string capitalize(string s) {
for (int i = 0; i < s.length(); i++) {
s[i] = toupper(s[i]);
}
return s;
}
string getName(string s) {
return capitalize(s.substr(0, s.find(' ', s.find(' ') + 1)));
}
int main() {
int n, u;
string oldName, newName;
bool valid = false;
cin >> n;
vector<string> oldList(n);
cin.ignore();
for (int i = 0; i < n; i++) {
getline(cin, oldList[i]);
}
cin >> u;
vector<string> newList(u);
cin.ignore();
for (int i = 0; i < u; i++) {
getline(cin, newList[i]);
}
vector<string> result;
for (int i = 0; i < n; i++) {
valid = false;
oldName = getName(oldList[i]);
for (int j = 0; j < u; j++) {
newName = getName(newList[j]);
if (oldName == newName) {
result.push_back(newList[j]);
valid = true;
}
}
if (!valid)
result.push_back(oldList[i]);
}
for (int i = 0; i < result.size(); i++) {
cout << result[i] << endl;
}
return 0;
}