本文主要是介绍习题5-11 更新字典(Updating a Dictionary,UVa12504),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原题链接:https://vjudge.net/problem/UVA-12504
分类:STL综合
备注:水题
前言:难得到了一个章节的后面这里还能有水题。
代码如下:
#include<string>
#include<sstream>
#include<iostream>
#include<cctype>
#include<set>
#include<map>
using namespace std;
int T;
int out(set<string>key, int type){char ch; if (!type)ch = '+';else if (type == 1)ch = '-';else ch = '*';if (key.size()) {cout << ch;for (set<string>::iterator it = key.begin(); it != key.end(); ++it) {if (it != key.begin())cout << ",";cout << *it;}cout << "\n";return 1;}return 0;
}
int main(void){cin >> T; getchar();string s;while(T--){getline(cin, s);for (int i = 0; i < s.length(); i++)if (!isalpha(s[i]) && !isdigit(s[i]))s[i] = ' ';set<string>store;map<string, string>match;stringstream ss(s);string a, b;while(ss>>a>>b){store.insert(a);match[a] = b;}getline(cin, s);for (int i = 0; i < s.length(); i++)if (!isalpha(s[i]) && !isdigit(s[i]))s[i] = ' ';stringstream ss2(s);set<string>add, del, change, store2;while (ss2 >> a >> b) {store2.insert(a);if (!store.count(a))add.insert(a);else if (match[a] != b)change.insert(a);}for (set<string>::iterator it = store.begin(); it != store.end(); ++it)if (!store2.count(*it))del.insert(*it);int flag = 0;if (out(add, 0))flag = 1;if (out(del, 1))flag = 1;if (out(change, 2))flag = 1;if (!flag)cout << "No changes\n";cout << "\n";}return 0;
}
这篇关于习题5-11 更新字典(Updating a Dictionary,UVa12504)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!