In this problem, a dictionary is collection of key-value pairs, where keys are lower-case letters, and values are non-negative integers. Given an old dictionary and a new dictionary, find out what were changed.

Each dictionary is formatting as follows:

{key:value,key:value,...,key:value}

Each key is a string of lower-case letters, and each value is a non-negative integer without leading zeros or prefix ‘+’. (i.e. -4, 03 and +77 are illegal). Each key will appear at most once, but keys can appear in any order.

Input

The first line contains the number of test cases T (T ≤ 1000). Each test case contains two lines. The first line contains the old dictionary, and the second line contains the new dictionary. Each line will contain at most 100 characters and will not contain any whitespace characters. Both dictionaries could be empty.

WARNING: there are no restrictions on the lengths of each key and value in the dictionary. That means keys could be really long and values could be really large.

Output

For each test case, print the changes, formatted as follows:

• First, if there are any new keys, print ‘+’ and then the new keys in increasing order (lexicographically), separated by commas.

• Second, if there are any removed keys, print ‘-’ and then the removed keys in increasing order (lexicographically), separated by commas.

• Last, if there are any keys with changed value, print ‘*’ and then these keys in increasing order (lexicographically), separated by commas.

If the two dictionaries are identical, print ‘No changes’ (without quotes) instead. Print a blank line after each test case.

Sample Input

3
{a:3,b:4,c:10,f:6}
{a:3,c:5,d:10,ee:4}
{x:1,xyz:123456789123456789123456789}
{xyz:123456789123456789123456789,x:1}
{first:1,second:2,third:3}
{third:3,second:2}

Sample Output

3
{a:3,b:4,c:10,f:6}
{a:3,c:5,d:10,ee:4}
{x:1,xyz:123456789123456789123456789}
{xyz:123456789123456789123456789,x:1}
{first:1,second:2,third:3}
{third:3,second:2}

HINT

思路很清晰,使用map<string,string>来存储键和值,一个用于存储新词典,一个用于储存旧词典。用两个数组分别储存修改的和新增的词。遍历新词典:

  • 如果新旧词典的键和值相同就删除旧词典的词
  • 如果新词典中有而旧词典中也有点值不相同,说明是修改的部分,将词存入数组,在旧词典中删除该词。
  • 如果旧词典中没有该词,说明是新增加的词,存入另一个数组,在旧词典中删除该词。
  • 遍历完成之后,旧词典中剩下的就是新词典中删除的词。

最后输出结果就可以了。

注意:每组数据之后都要输出一个空行,包括最后一行。

Accepted

#include<bits/stdc++.h>
using namespace std;
int main() {
ofstream fcout;
fcout.open("temp.txt");
int num;
string s, s1, s2;
map<string, string>old, news;
vector<string>newkey,rekey;
cin >> num;getchar();
while (num--){
int flag = 0;
old.clear();news.clear();rekey.clear();newkey.clear();
cin >> s1 >> s2;
for (int i = 0;i < s1.length();i++)if (s1[i] == '{' || s1[i] == '}' || s1[i] == ',' || s1[i] == ':')s1[i] = ' ';
for (int i = 0;i < s2.length();i++)if (s2[i] == '{' || s2[i] == '}' || s2[i] == ',' || s2[i] == ':')s2[i] = ' ';
stringstream ss1(s1), ss2(s2);
while (ss1 >> s1 >> s2)old[s1] = s2;
while (ss2 >> s1 >> s2)news[s1] = s2;
for (auto i = news.begin();i != news.end();i++ ) {
if (old.count(i->first) && old[i->first] == i->second)old.erase(i->first);
else if (old.count(i->first) && old[i->first] != i->second) { rekey.push_back(i->first);old.erase(i->first); }
else if (!old.count(i->first))newkey.push_back(i->first);
}
if (newkey.size()) {
for (int i = 0;i < newkey.size();i++) cout << (i == 0 ? '+' : ',') << newkey[i];
cout << endl;
}
if (old.size()) {
for (auto i = old.begin();i != old.end();i++)cout << (i == old.begin() ? '-' : ',') << i->first;
cout << endl;
}
if (rekey.size()) {
for (int i = 0;i < rekey.size();i++) cout << (i == 0 ? '*' : ',') << rekey[i];
cout << endl;
} if (!newkey.size() && !rekey.size() && !old.size())cout << "No changes" << endl;
cout << endl;
} }

最新文章

  1. WPF 如何绘制不规则按钮,并且有效点击范围也是不规则的
  2. Advice for students of machine learning--转
  3. 【iCore3 双核心板】例程二十:LAN_TCPC实验——以太网数据传输
  4. DataGridView 行、列的隐藏和删除
  5. mac 下终端访问文件出现“Permission Denied”解决方案
  6. ASP.NET四则运算--工厂模式
  7. STM32中断控制及优先级设置
  8. iOS学习之C语言分支结构
  9. API之IP地址查询---权威的IP地址查询接口集合
  10. UNIX环境高级编程——网络编程常用函数及结构
  11. ansible-playbook用法
  12. java中接口和抽象类的异同点
  13. nodeJs --- web服务器创建
  14. switch选择结构
  15. UOJ400/LOJ2553 CTSC2018 暴力写挂 边分治、虚树
  16. 超哥带你学GIT
  17. oracle修改日期格式
  18. Module build failed: Error: No PostCSS Config found
  19. 【CF600E】 Lomsat gelral
  20. php $_FILES处理文件上传

热门文章

  1. 在 2021 年你需要掌握的 7 种关于 JavaScript 的数组方法
  2. Vue学习笔记-nodejs+vue-cli4+webpack按装配置+项目创建
  3. Ping 的工作原理你懂了,那 ICMP 你懂不懂?
  4. vue高级
  5. java 阿里云短信发送
  6. 微信小程序一周时间表
  7. 小程序setData中key用变量
  8. 设计模式(二十四)——职责链模式(SpringMVC源码分析)
  9. PHP配置 3. 配置open_basedir
  10. Codeforces Round #574 (Div. 2) E. OpenStreetMap 【单调队列】