-
Notifications
You must be signed in to change notification settings - Fork 5
/
UVA-12504.cpp
81 lines (79 loc) · 1.57 KB
/
UVA-12504.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
72
73
74
75
76
77
78
79
80
81
#include<iostream>
#include<string>
#include<map>
#include<sstream>
using namespace std;
void getMap(map<string, string> & mp, string &line) {
int i, j, k;
for(i = 0; i < line.length(); ++i) {
if((line[i] < 'a' || line[i] > 'z') && (line[i] < '0' || line[i] > '9')) {
line[i] = ' ';
}
}
stringstream ss(line);
string word1, word2;
while(ss >> word1 >> word2) {
mp[word1] = word2;
}
}
int main() {
int n;
bool flag[3];
cin >> n;
string line1, line2;
getline(cin, line1);
while(n--) {
getline(cin, line1);
getline(cin, line2);
map<string, string> mp1, mp2;
getMap(mp1, line1);
getMap(mp2, line2);
flag[0] = false;
flag[1] = false;
flag[2] = false;
for(auto i = mp2.begin(); i !=mp2.end(); ++i) {
if(!mp1.count(i->first)) {
if(flag[0] == false) {
flag[0] = true;
cout << "+" << i->first;
} else {
cout << ',' << i->first;
}
}
}
if(flag[0] == true) {
cout << endl;
}
for(auto i = mp1.begin(); i !=mp1.end(); ++i) {
if(!mp2.count(i->first)) {
if(flag[1] == false) {
flag[1] = true;
cout << "-" << i->first;
} else {
cout << ',' << i->first;
}
}
}
if(flag[1] == true) {
cout << endl;
}
for(auto i = mp2.begin(); i !=mp2.end(); ++i) {
if(mp1.count(i->first) && i->second != mp1[i->first]) {
if(flag[2] == false) {
flag[2] = true;
cout << "*" << i->first;
} else {
cout << ',' << i->first;
}
}
}
if(flag[2] == true) {
cout << endl;
}
if(!flag[0] && !flag[1] && !flag[2]) {
cout << "No changes" << endl;
}
cout << endl;
}
return 0;
}