Updating a Dictionary 

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 (   T1000). 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

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

Sample Output

  1. +d,ee
  2. -b,f
  3. *c
  4.  
  5. No changes
  6.  
  7. -first

  8. 题目大意:每次给2个字符串,字符串里的内容表示为key:value对,顺序随意,比较2个字符串里的内容判断增加了那些,减少了那些,key值对应的value变了的有哪些。水题,字符串处理,烦!
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<string>
  4. #include<string.h>
  5. #include<cstring>
  6. #include<sstream>
  7. #include<algorithm>
  8. using namespace std;
  9. struct A
  10. {
  11. string key;
  12. string value;
  13. int same(A &b){
  14. if(key==b.key){
  15. if(value==b.value)return ;//no change
  16. else return ;//change
  17. }
  18. else{//not same
  19. if(key<b.key)return ;
  20. else return ;
  21. }
  22. }
  23. void set(string a,string b){
  24. key=a;
  25. value=b;
  26. }
  27. };
  28. bool cmp(A a,A b){
  29. return a.key<b.key;
  30. }//比较函数一定不要用&同名引用
  31. void xiu(string &A){
  32. A=A.substr(,A.length()-);
  33. for(int i=A.length()-;i>=;i--){
  34. if(A[i]==',' || A[i]==':')A[i]=' ';
  35. }
  36. }
  37. int main(){
  38. int T;cin>>T;
  39. string str1;
  40. string str2;
  41. string value,key;
  42. getline(cin,str1);
  43. while(T--){
  44. getline(cin,str1);
  45. getline(cin,str2);
  46. xiu(str1);
  47. xiu(str2);
  48. istringstream in1(str1);
  49. istringstream in2(str2);
  50. A x1[],x2[];
  51. int i=;
  52. while(in1>>key>>value){
  53. x1[i++].set(key,value);
  54. }
  55. int j=;
  56. while(in2>>key>>value){
  57. x2[j++].set(key,value);
  58. }
  59. sort(x1,x1+i,cmp);
  60. sort(x2,x2+j,cmp);
  61. string add[];int add_num=;
  62. string sub[];int sub_num=;
  63. string cha[];int cha_num=;
  64. int ii=,jj=;
  65. while(ii<i && jj<j){
  66. switch(x1[ii].same(x2[jj])){
  67. case :ii++,jj++;break;
  68. case :cha[cha_num++]=x1[ii].key;ii++,jj++;break;
  69. case :sub[sub_num++]=x1[ii].key;ii++;break;
  70. case :add[add_num++]=x2[jj].key;jj++;break;
  71. default:break;
  72. }
  73. }
  74. while(ii<i){
  75. sub[sub_num++]=x1[ii++].key;
  76. }
  77. while(jj<j){
  78. add[add_num++]=x2[jj++].key;
  79. }
  80. if(add_num+sub_num+cha_num==)cout<<"No changes\n\n";
  81. else{
  82. if(add_num!=){
  83. cout<<"+"<<add[];
  84. for(int k=;k<add_num;k++){
  85. cout<<','<<add[k];
  86. }
  87. cout<<'\n';
  88. }
  89. if(sub_num!=){
  90. cout<<"-"<<sub[];
  91. for(int k=;k<sub_num;k++){
  92. cout<<','<<sub[k];
  93. }
  94. cout<<'\n';
  95. }
  96. if(cha_num!=){
  97. cout<<'*'<<cha[];
  98. for(int k=;k<cha_num;k++){
  99. cout<<','<<cha[k];
  100. }
  101. cout<<'\n';
  102. }
  103. cout<<'\n';
  104. }
  105. }return ;
  106. }

[ACM_模拟] UVA 12504 Updating a Dictionary [字符串处理 字典增加、减少、改变问题]的更多相关文章

  1. Uva - 12504 - Updating a Dictionary

    全是字符串相关处理,截取长度等相关操作的练习 AC代码: #include <iostream> #include <cstdio> #include <cstdlib& ...

  2. Uva 511 Updating a Dictionary

    大致题意:用{ key:value, key:value, key:value }的形式表示一个字典key表示建,在一个字典内没有重复,value则可能重复 题目输入两个字典,如{a:3,b:4,c: ...

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

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

  4. [ACM_模拟] UVA 10881 Piotr's Ants[蚂蚁移动 数组映射 排序技巧]

    "One thing is for certain: there is no stopping them;the ants will soon be here. And I, for one ...

  5. [ACM_模拟] UVA 12503 Robot Instructions [指令控制坐标轴上机器人移动 水]

      Robot Instructions  You have a robot standing on the origin of x axis. The robot will be given som ...

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

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

  7. csuoj 1113: Updating a Dictionary

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

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

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

  9. [Swift]JSON字符串与字典(Dictionary)、数组(Array)之间的相互转换

    1.JSON字符串与字典(Dictionary)之间的相互转换 import Foundation //JSON字符串转换为字典(Dictionary) func getDictionaryFromJ ...

随机推荐

  1. Windows phone 自定义用户控件(UserControl)——ColorPicker

    编码前 学习Windows phone自定义用户控件,在<WPF编程宝典>学习的小例子.并根据windows phone稍微的不同,做了点修改.ColorPicker(颜色拾取器):拥有三 ...

  2. sqlite小知识

    删除数据时,由于缓存关系,数据了文件大小不会一下子减小,可以通过执行vacuum;或新建表时使用自动整理大小来实现. sqlite的大小理论上可以达到140T. 暂时,使用C的api,只能使用不是.开 ...

  3. 41-json.decoder.JSONDecodeError: Invalid control character at: line 6894 column 12 (char 186418)

    在使用python中将单词本的单词用正则匹配成字典后,以json存储,仪json读入,但是一直报错: 原因是: 正则处理后的数据有的出了点问题,导致一个字典的 有多个相同的键!!!,则肯定会报错啊!! ...

  4. cmake 总结

    cmake中一些预定义变量 PROJECT_SOURCE_DIR 工程的根目录 PROJECT_BINARY_DIR 运行cmake命令的目录,通常是${PROJECT_SOURCE_DIR}/bui ...

  5. php ZeroMQ 的使用

    一.ZeroMQ简介 ZMQ (以下 ZeroMQ 简称 ZMQ)是一个简单好用的传输层,像框架一样的一个 Socket Library,他使得 Socket 编程更加简单.简洁和性能更高.是一个消息 ...

  6. redhat配置java环境

    1.检查是否有旧版本的jdk java -version java version "1.4.2" gij (GNU libgcj) version (Red Hat -) Cop ...

  7. Jmeter发送某个request时而成功,时而失败(处理办法:失败的时候尝试重新发送这个HTTP request)

    Jmeter发送某个request时而成功,时而失败 Maybe it’s Jmeter’s problem, after all, is not a commercial software. And ...

  8. 并发编程(三)Promise, Future 和 Callback

    并发编程(三)Promise, Future 和 Callback 异步操作的有两个经典接口:Future 和 Promise,其中的 Future 表示一个可能还没有实际完成的异步任务的结果,针对这 ...

  9. Java NIO系列教程(十一) Java NIO 与 IO

    Java NIO系列教程(十一) Java NIO与IO 当学习了 Java NIO 和 IO 的 API 后,一个问题马上涌入脑海: 我应该何时使用 IO,何时使用 NIO 呢?在本文中,我会尽量清 ...

  10. Mockplus是如何节省你的原型时间的?

    还在用老牌原型工具一点点绘制产品原型吗?还在为实现一个满意的交互而绞尽脑汁吗?还在为无法和用户高效沟通而发愁吗?朋友,现在是快速原型的时代了.时间不等人,当你精雕细琢完成产品启动页的时候,别人的原型已 ...