#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
vector<string> out[3];
map<string, string> ostr;
map<string, string> nstr;
char outFlag[3] = { '+','-','*' };
string key, value;
int cnt = 0;
void Init() {
for (int i = 0; i < 3; ++i) out[i].clear();
ostr.clear();
nstr.clear();
cnt = 0;
}
void GetMapTree(string &in, map<string, string> &tree) {
key = value = "";
int flag = 0;
for (int i = 0; i < in.size(); ++i) {
if(in[i] == '{' || in[i] == '}') continue;
while (in[i] != ':') key += in[i++];i++;
while (in[i] != ',' && in[i] != '}') value += in[i++];
tree[key] = value;
key = value = "";
}
}
void Print(int index, char ch) {
vector<string>& a = out[index];
if (a.empty()) return;
for (int i = 0; i < a.size(); ++i) {
if (!i) { cout << ch; }
else cout << ",";
cout << a[i];
}
cout << endl;
}
int main()
{
int n;
cin >> n; cin.ignore();
string old, ne;
while (n--) {
Init();
getline(cin, old);getline(cin, ne);
GetMapTree(old, ostr);GetMapTree(ne, nstr);
for (auto it = nstr.begin();it != nstr.end();++it)
{
if (ostr[it->first] == "") { out[0].emplace_back(it->first); cnt++; }
else if (ostr[it->first] != it->second) { out[2].emplace_back(it->first); cnt++; }
ostr[it->first] = "";
}
for (auto it = ostr.begin(); it != ostr.end(); ++it) {
if (it->second != "") { out[1].emplace_back(it->first); cnt++; }
}
if (cnt == 0) cout << "No changes" << endl;
else {
for (int i = 0; i < 3; ++i)Print(i, outFlag[i]);
}
cout << endl;
}
return 0;
}
习题5-11(uva-12504)
最新推荐文章于 2021-05-19 12:30:55 发布