传送门

Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu

Description

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

------------------------------------------------------------------------------

简单题,注意implementation。 

------------------------------------------------------------------------------
 WA
#include <cstdio>
#include <iostream>
#include <cctype>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#define pb push_back using namespace std;
map<string, string> a, b;
vector<string> aa, bb;
int main(){
//freopen("in", "r", stdin);
int T;
string s, t;
char ch;
for(cin>>T; T--; cout<<endl){
for(;cin>>ch;){
if(isalpha(ch)) s+=ch;
else if(ch==':'){
while(cin>>ch, isdigit(ch)){
t+=ch;
}
a[s]=t;
aa.pb(s);
s.clear();
t.clear();
if(ch=='}') break; //error
}
}
for(;cin>>ch;){
if(isalpha(ch)) s+=ch;
else if(ch==':'){
while(cin>>ch, isdigit(ch)){
t+=ch;
}
bb.pb(s);
b[s]=t;
s.clear();
t.clear();
if(ch=='}') break; //error
}
}
sort(aa.begin(), aa.end());
sort(bb.begin(), bb.end());
bool fir=true, nc=true;
for(int i=; i<bb.size(); i++){
string &tmp=bb[i];
if(a[tmp].empty()){
if(fir) cout<<'+'+tmp, fir=false;
else cout<<','+tmp;
}
}
if(!fir) cout<<endl, nc=;
fir=true;
for(int i=; i<aa.size(); i++){
string &tmp=aa[i];
if(b[tmp].empty()){
if(fir) cout<<'-'+tmp, fir=false;
else cout<<','+tmp;
}
}
if(!fir) cout<<endl, nc=;
fir=true;
for(int i=; i<bb.size(); i++){
string &tmp=bb[i];
if(!a[tmp].empty()&&!b[tmp].empty()&&a[tmp]!=b[tmp]){
if(fir) cout<<'*'+tmp, fir=false;
else cout<<','+tmp;
}
}
if(!fir) cout<<endl, nc=;
if(nc) cout<<"No changes"<<endl;
a.clear(), b.clear(), aa.clear(), bb.clear();
} }
 AC 
#include <cstdio>
#include <iostream>
#include <cctype>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#define pb push_back using namespace std;
map<string, string> a, b;
vector<string> aa, bb;
int main(){
freopen("in", "r", stdin);
int T;
string s, t;
char ch;
for(cin>>T; T--; cout<<endl){
for(;cin>>ch;){
if(isalpha(ch)) s+=ch;
else if(ch==':'){
while(cin>>ch, isdigit(ch)){
t+=ch;
}
a[s]=t;
aa.pb(s);
s.clear();
t.clear();
}
if(ch=='}') break;
}
//cout<<aa.size()<<endl;
for(;cin>>ch;){
if(isalpha(ch)) s+=ch;
else if(ch==':'){
while(cin>>ch, isdigit(ch)){
t+=ch;
}
bb.pb(s);
b[s]=t;
s.clear();
t.clear();
}
if(ch=='}') break;
}
sort(aa.begin(), aa.end());
sort(bb.begin(), bb.end());
bool fir=true, nc=true;
for(int i=; i<bb.size(); i++){
string &tmp=bb[i];
if(a[tmp].empty()){
if(fir) cout<<'+'+tmp, fir=false;
else cout<<','+tmp;
}
}
if(!fir) cout<<endl, nc=;
fir=true;
for(int i=; i<aa.size(); i++){
string &tmp=aa[i];
if(b[tmp].empty()){
if(fir) cout<<'-'+tmp, fir=false;
else cout<<','+tmp;
}
}
if(!fir) cout<<endl, nc=;
fir=true;
for(int i=; i<bb.size(); i++){
string &tmp=bb[i];
if(!a[tmp].empty()&&!b[tmp].empty()&&a[tmp]!=b[tmp]){
if(fir) cout<<'*'+tmp, fir=false;
else cout<<','+tmp;
}
}
if(!fir) cout<<endl, nc=;
if(nc) cout<<"No changes"<<endl;
a.clear(), b.clear(), aa.clear(), bb.clear();
}
}

CSU 1113 Updating a Dictionary的更多相关文章

  1. CSU 1113 Updating a Dictionary(map容器应用)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 解题报告:输入两个字符串,第一个是原来的字典,第二个是新字典,字典中的元素的格式为 ...

  2. csuoj 1113: Updating a Dictionary

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

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

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

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

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

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

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

  6. Problem C Updating a Dictionary

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

  7. Updating a Dictionary UVA - 12504

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

  8. Uva 511 Updating a Dictionary

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

  9. Uva - 12504 - Updating a Dictionary

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

随机推荐

  1. 006医疗项目-模块一:用户的查找:2.用户表查询的mapper映射的文件

    前一篇文章已经把sql语句写好了并且在PL/SQL上调试过了,是可以的.这篇文章是写对应的mapper.xml, 第一步我们先通过逆向工程去构建每个表的mapper.xml文件和pojo类.这个我们在 ...

  2. 22Mybatis_订单商品数据模型_多对多查询以及对多对多查询的总结

    之前讲了一对一,一对多查询,这篇文章讲的是多对多. 先给出需求:查询用户及用户购买商品信息. 我们由之前的文章知道,这个需求是多对多的. 还是那个终止我们的mybatis所做的不管是之前的一对一还是一 ...

  3. 将博客搬至CSDN(放弃)

    将博客搬至CSDN需要发这篇文章,但是到现在CSDN还没给我发通知,因为急着要记东西,所以不搬了,继续写我下一篇随笔.

  4. discuz编码转换UTF8与GBK互转完美适合Discuz3.x系列

    由于一些网站通信编码的问题不得不把一直使用的网站编码由UTF8转为GBK,在转换过程中在官方看了很多方法,自己也都尝试了一些最后都没有能够成功,数据库的转换一直都是没有大问题,不存在丢失什么的,能看到 ...

  5. Dottrace跟踪代码执行时间

    当自己程序遇到性能问题,比如请求反应缓慢,怎么分析是哪里出了问题呢?dottrace可以帮助.net程序跟踪出代码里每个方法的执行时间,这样让我们更清晰的看出是哪里执行时间过长,然后再分析应该怎样解决 ...

  6. python 操作注册表

    import win32api import win32con keyname = r'Software\Microsoft\Internet Explorer\Main' page = 'www.l ...

  7. GDB深入研究——20135308芦畅

    GDB深入研究 一.GDB代码调试 (一)GDB调试实例 在终端中编译一个示例C语言小程序,保存到文件 gdb-sample.c 中,用GCC编译之 #include <stdio.h> ...

  8. (转)shell实例手册

    原文地址:http://hi.baidu.com/quanzhou722/item/f4a4f3c9eb37f02d46d5c0d9 实在是太好的资料了,不得不转 shell实例手册 0说明{ 手册制 ...

  9. JavaScript并非“按值传递”

    置顶文章:<纯CSS打造银色MacBook Air(完整版)> 上一篇:<拥Bootstrap入怀--模态框(modal)篇> 作者主页:myvin 博主QQ:85139910 ...

  10. windows 7 + vs2010 sp1编译 x64位版qt4

    由于qt官方没有发布预编译的64位版qt4,要使用64位版qt4,只能自己编译,编译过程如下: 1,下载源码并解压到D:\qt-src\qt-everywhere-opensource-src-4.8 ...