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

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

题目大意:每次给2个字符串,字符串里的内容表示为key:value对,顺序随意,比较2个字符串里的内容判断增加了那些,减少了那些,key值对应的value变了的有哪些。水题,字符串处理,烦!
 #include<iostream>
#include<cstdio>
#include<string>
#include<string.h>
#include<cstring>
#include<sstream>
#include<algorithm>
using namespace std;
struct A
{
string key;
string value;
int same(A &b){
if(key==b.key){
if(value==b.value)return ;//no change
else return ;//change
}
else{//not same
if(key<b.key)return ;
else return ;
}
}
void set(string a,string b){
key=a;
value=b;
}
};
bool cmp(A a,A b){
return a.key<b.key;
}//比较函数一定不要用&同名引用
void xiu(string &A){
A=A.substr(,A.length()-);
for(int i=A.length()-;i>=;i--){
if(A[i]==',' || A[i]==':')A[i]=' ';
}
}
int main(){
int T;cin>>T;
string str1;
string str2;
string value,key;
getline(cin,str1);
while(T--){
getline(cin,str1);
getline(cin,str2);
xiu(str1);
xiu(str2);
istringstream in1(str1);
istringstream in2(str2);
A x1[],x2[];
int i=;
while(in1>>key>>value){
x1[i++].set(key,value);
}
int j=;
while(in2>>key>>value){
x2[j++].set(key,value);
}
sort(x1,x1+i,cmp);
sort(x2,x2+j,cmp);
string add[];int add_num=;
string sub[];int sub_num=;
string cha[];int cha_num=;
int ii=,jj=;
while(ii<i && jj<j){
switch(x1[ii].same(x2[jj])){
case :ii++,jj++;break;
case :cha[cha_num++]=x1[ii].key;ii++,jj++;break;
case :sub[sub_num++]=x1[ii].key;ii++;break;
case :add[add_num++]=x2[jj].key;jj++;break;
default:break;
}
}
while(ii<i){
sub[sub_num++]=x1[ii++].key;
}
while(jj<j){
add[add_num++]=x2[jj++].key;
}
if(add_num+sub_num+cha_num==)cout<<"No changes\n\n";
else{
if(add_num!=){
cout<<"+"<<add[];
for(int k=;k<add_num;k++){
cout<<','<<add[k];
}
cout<<'\n';
}
if(sub_num!=){
cout<<"-"<<sub[];
for(int k=;k<sub_num;k++){
cout<<','<<sub[k];
}
cout<<'\n';
}
if(cha_num!=){
cout<<'*'<<cha[];
for(int k=;k<cha_num;k++){
cout<<','<<cha[k];
}
cout<<'\n';
}
cout<<'\n';
}
}return ;
}

[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. ORACLE 对一个表进行循环查数,再根据MO供给数量写入另一个新表

    一. 加工处理后要变成如下效果 create table test1 (sonum varchar2(10),lineid varchar2(10),qty int ,qty2 int ,remark ...

  2. 基于MSAA的QQ界面信息获取的实现

    主要技术(Microsoft Active Accessibility)讲解: 以下是微软对于此技术的说明 Microsoft Active Accessibility Version 2.0 Pur ...

  3. Java集合set的并、交、差操作

    集合的并.交.差操作 Set<Integer> result = new HashSet<Integer>(); Set<Integer> set1 = new H ...

  4. clipboard.js复制文字

    A-固定内容: <script type="text/javascript" src="script/clipboard.min.js"></ ...

  5. codeblocks 更换颜色主题

    关闭codeblocks,下载主题文件(colour_themes.conf).在关闭codeblocks的情况下,linux下的~/.config/codeblocks/下有个conf文件,将其备份 ...

  6. Array Product(模拟)

    Array Product http://codeforces.com/problemset/problem/1042/C You are given an array aa consisting o ...

  7. Spring编程式事务管理

    --------------------siwuxie095                                 Spring 编程式事务管理         以转账为例         ...

  8. MonkeyRunner原理初步--Android自动化测试学习历程

    章节:自动化基础篇——MonkeyRunner原理初步 主要讲解内容及笔记: 一.理论知识和脚本演示 最佳方式是上官网文档去查看monkeyrunner的介绍,官网上不去,就找了一个本地的androi ...

  9. struts框架值栈问题七之EL表达式也会获取到值栈中的数据

    7. 问题七:为什么EL也能访问值栈中的数据? * StrutsPreparedAndExecuteFilter的doFilter代码中 request = prepare.wrapRequest(r ...

  10. smrtlink

    SMRT Link is the web-based end-to-end workflow manager for the Sequel™ System. It includes software ...