题意:对比新老字典的区别:内容多了、少了还是修改了。
代码:(Accepted,0.000s)
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
|
#include<iostream> #include<sstream> #include<string> #include<vector> #include<map> using namespace std;
int T; int main() { #ifdef _XieNaoban_ freopen("in.txt", "r", stdin); #endif ios::sync_with_stdio(false); cin >> T; cin.ignore(); while (T--) { map<string, string> dic; for (int i(0);i < 2;++i) { string line, key, value; getline(cin, line); for (auto &r : line) if (r == ',' || r == ':' || r == '{' || r == '}') r = ' '; istringstream in(line); while (in >> key) { in >> value; if (i) { auto d(dic.find(key)); if (d != dic.end()) { if (d->second != value) d->second = "*"; else d->second = '&'; } else dic[key] = "+"; } else dic[key] = value; } } vector<string> inc, rmv, chg; for (const auto& r : dic) switch (r.second[0]) { case '+': inc.push_back(r.first);break; case '*': chg.push_back(r.first);break; case '&': break; default: rmv.push_back(r.first);break; } if (inc.empty() && rmv.empty() && chg.empty()) cout << "No changes\n"; else { if (!inc.empty()) { cout << '+' << inc[0]; for (auto i(inc.begin() + 1);i != inc.end();++i) cout << ',' << *i; cout << '\n'; } if (!rmv.empty()) { cout << '-' << rmv[0]; for (auto i(rmv.begin() + 1);i != rmv.end();++i) cout << ',' << *i; cout << '\n'; } if (!chg.empty()) { cout << '*' << chg[0]; for (auto i(chg.begin() + 1);i != chg.end();++i) cout << ',' << *i; cout << '\n'; } } cout << '\n'; } return 0; }
|
分析:这题很水,轻松AC,没啥好说的。