难度:3
比较简单的一道题,代码里面有很多可以复制粘贴的地方。
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pa;
void solve(string &s, map<string, string> &mp) {
for (auto& p : s) {
if (p == ',' || p == '{' || p == '}') p = ' ';
}
stringstream ss(s);
string t;
while (ss >> t) {
int pos = t.find(':');
mp[t.substr(0, pos)] = t.substr(pos + 1, t.size() - pos - 1);
}
}
int main() {
int t;
cin >> t;
while (t--) {
map<string, string> mp1, mp2;
string s1, s2;
cin >> s1 >> s2;
solve(s1, mp1);
solve(s2, mp2);
vector<string> v1, v2, v3;
for (map<string, string>::iterator it = mp2.begin(); it != mp2.end(); it++) {
if (mp1.find(it->fi) == mp1.end()) v1.pb(it->fi);
}
for (map<string, string>::iterator it = mp1.begin(); it != mp1.end(); it++) {
if (mp2.find(it->fi) == mp2.end()) v2.pb(it->fi);
}
for (map<string, string>::iterator it = mp1.begin(); it != mp1.end(); it++) {
if (mp2.find(it->fi) != mp2.end() && mp2[it->fi] != it->se) v3.pb(it->fi);
}
if ((int) v1.size() == 0 && (int) v2.size() == 0 && (int) v3.size() == 0) cout << "No changes\n";
else {
if ((int) v1.size()) {
for (int i = 0; i < (int) v1.size(); i++) {
cout << (i == 0 ? "+" : ",") << v1[i];
}
cout << endl;
}
if ((int) v2.size()) {
for (int i = 0; i < (int) v2.size(); i++) {
cout << (i == 0 ? "-" : ",") << v2[i];
}
cout << endl;
}
if ((int) v3.size()) {
for (int i = 0; i < (int) v3.size(); i++) {
cout << (i == 0 ? "*" : ",") << v3[i];
}
cout << endl;
}
}
cout << endl;
}
return 0;
}