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
+d,ee
-b,f
*c

No changes

-first
直接模拟即可,这里用到了map,queue,string,stringstream,总之全用的标准库(咳咳咳),打算在重新写一份代码(代码待补),不借助map和queue,还有一件事,这道题提交了好多次都是WA。。。然后就把题读了好几遍,没发现什么特殊的情况存在,然后注释掉了一句代码就过了,std::ios::sync_with_stdio(false),就这句,解除cin与stdin的同步,据说会加快cin的速度,我怕会超时就把这段代码加上了(最后80ms),结果问题就出在这了,还有就是换行cout不用<<endl貌似也能加快速度。。。

代码:

#include<iostream>
#include<sstream>
#include<string>
#include<queue>
#include<map>
using namespace std; map<string,string> mp1,mp2;
typedef queue<string> Queue;
Queue New,Change,None; void Replace(string &str){
int len = str.size();
for(int i=;i<len;i++)
if(str[i] == ':'|| str[i]=='{' || str[i]=='}' || str[i] == ',') str[i] = ' ';
} void String_work(string &pre,string now){
Replace(pre); Replace(now);
stringstream ss(pre),mm(now);
string tmp,str;
while(ss >> str){
ss >> tmp;
mp1[str] = tmp;
}
while(mm >> str){
mm >> tmp;
mp2[str] = tmp;
}
} void Add_to_queue(){
map<string,string> ::iterator it;
for(it=mp2.begin();it!=mp2.end();it++){
if(mp1.find((*it).first)==mp1.end())
New.push((*it).first);
else if(mp1[(*it).first]!=(*it).second) {
Change.push((*it).first);
mp1.erase((*it).first);
}
else mp1.erase((*it).first); }
for(it=mp1.begin();it!=mp1.end();it++){
None.push((*it).first);
}
} void print_ans(Queue &Q,char c){
cout<< c;
while(!Q.empty()){
cout << Q.front(); Q.pop();
if(Q.empty()) cout << "\n" ; else cout <<",";
}
} void Solve_question(){
bool flag = true;
if(!New.empty()) {flag = false; print_ans(New,'+');}
if(!None.empty()) {flag = false; print_ans(None,'-');}
if(!Change.empty()) {flag = false; print_ans(Change,'*');}
if(flag) cout <<"No changes\n";
cout <<"\n";
} void Init_map(){
mp1.clear(); mp2.clear();
} int main(){
//std::ios::sync_with_stdio(false);!!!不能用!!!切记!!!
int T;
string pre,now;
cin >> T;
while(T--){
Init_map();
cin >> pre >> now;
String_work(pre,now);
Add_to_queue();
Solve_question();
}
}


H-Updating a Dictionary (模拟)的更多相关文章

  1. [ACM_模拟] UVA 12504 Updating a Dictionary [字符串处理 字典增加、减少、改变问题]

      Updating a Dictionary  In this problem, a dictionary is collection of key-value pairs, where keys ...

  2. Problem C Updating a Dictionary

    Problem C     Updating a Dictionary In this problem, a dictionary is collection of key-value pairs, ...

  3. csuoj 1113: Updating a Dictionary

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 1113: Updating a Dictionary Time Limit: 1 Sec  ...

  4. 湖南生第八届大学生程序设计大赛原题 C-Updating a Dictionary(UVA12504 - Updating a Dictionary)

    UVA12504 - Updating a Dictionary 给出两个字符串,以相同的格式表示原字典和更新后的字典.要求找出新字典和旧字典的不同,以规定的格式输出. 算法操作: (1)处理旧字典, ...

  5. [刷题]算法竞赛入门经典(第2版) 5-11/UVa12504 - Updating a Dictionary

    题意:对比新老字典的区别:内容多了.少了还是修改了. 代码:(Accepted,0.000s) //UVa12504 - Updating a Dictionary //#define _XieNao ...

  6. Updating a Dictionary UVA - 12504

    In this problem, a dictionary is collection of key-value pairs, where keys are lower-case letters, a ...

  7. CSU 1113 Updating a Dictionary

    传送门 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Description In th ...

  8. H.数7(模拟)

    1212: H.数7 时间限制: 1 Sec  内存限制: 64 MB 提交: 8  解决: 5 标签提交统计讨论版 题目描述 数7是一个简单的饭桌游戏,有很多人围成一桌,先从任意一人开始数数,1.2 ...

  9. 【UVA】12504 Updating a Dictionary(STL)

    题目 题目     分析 第一次用stringstream,真TMD的好用     代码 #include <bits/stdc++.h> using namespace std; int ...

随机推荐

  1. js 变量类型

    变量类型分为:基础类型和引用类型 基础类型:boolean, string, number, null, undefined, symbol 引用类型: array, object typeof: 判 ...

  2. 【Luogu4299】首都

    BZOJ权限题. 洛谷 题目描述 在X星球上有N个国家,每个国家占据着X星球的一座城市.由于国家之间是敌对关系,所以不同国家的两个城市是不会有公路相连的. X星球上战乱频发,如果A国打败了B国,那么B ...

  3. Python---TKinter项目实战---屏保

    ### 项目分析 - 屏保可以自己启动,也可以手动启动 - 一旦敲击键盘或者移动鼠标后,或者其他的引发时间,则停止 - 如果屏保是一幅画的话,则没有画框 - 图像的动作是随机的,具有随机性,可能包括颜 ...

  4. Linux内核设计与实现 总结笔记(第十四章)块I/O层

    一.剖析一个块设备 块设备最小的可寻址单元是扇区. 扇区大小一般是2的整数倍,最常见的是512字节. 因为各种软件的用途不同,所以他们都会用到自己的最小逻辑可寻址单元----块.块只能基于文件系统,是 ...

  5. BZOJ 2427: [HAOI2010]软件安装 tarjan + 树形背包

    Description 现在我们的手头有N个软件,对于一个软件i,它要占用Wi的磁盘空间,它的价值为Vi.我们希望从中选择一些软件安装到一台磁盘容量为M计算机上,使得这些软件的价值尽可能大(即Vi的和 ...

  6. JS onclick中this用法

    当在dom元素中使用onclick绑定事件的时候,可以使用this来指向该元素对象. 打印输出的内容为: 所以可以通过该this对象来获取子元素 //通过element获取该对象下的一个audio标签 ...

  7. CG-CTF | SQL Injection

    没错我又偷偷写了道web[并查集好难啊,脑阔疼QAQ] http://chinalover.sinaapp.com/web15/index.php?username=%5C&password= ...

  8. mui初级入门教程(六)— 模板页面实现原理及多端适配指南

    文章来源:小青年原创发布时间:2016-07-26关键词:mui,webview,template,os,多端适配转载需标注本文原始地址: http://zhaomenghuan.github.io. ...

  9. ORACLE DG 库参数db_file_name_convert和log_file_name_convert的作用

    https://www.cnblogs.com/xqzt/p/5089826.html ORACLE DG 库参数db_file_name_convert和log_file_name_convert的 ...

  10. Ajax的封装。

    封装 Ajax 因为Ajax 使用起来比较麻烦,主要就是参数问题,比如到底使用GET 还是POST:到 底是使用同步还是异步等等,我们需要封装一个Ajax 函数,来方便我们调用.    封装支持接收来 ...