CSU 1113 Updating a Dictionary
来源:互联网 发布:淘宝订单险是什么意思 编辑:程序博客网 时间:2024/05/22 01:27
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*cNo changes-first
简单的枚举即可。
#include<stdio.h>#include<algorithm>#include<iostream>#include<cstring>#include<string>#include<map>using namespace std;const int maxn=1005;map<string,string> a,b;map<string,string>::iterator i;string s1,s2;char s[maxn];bool check(char c){if (c=='{'||c=='}'||c==','||c==':')return false;return true;}int t1,t2,T,F,f;int main(){scanf("%d",&T);while (T--){a.clear();b.clear();F=t1=t2=0;scanf("%s",s);for (int i=0;s[i];i++){if (!check(s[i])) continue;for (s1="";check(s[i]);i++) s1=s1+s[i];for (i++,s2="";check(s[i]);i++) s2=s2+s[i];a[s1]=s2;}scanf("%s",s);for (int i=0;s[i];i++){if (!check(s[i])) continue;for (s1="";check(s[i]);i++) s1=s1+s[i];for (i++,s2="";check(s[i]);i++) s2=s2+s[i];b[s1]=s2;}f=0;for (i=b.begin();i!=b.end();i++){if (a.find(i->first)==a.end()){printf("%c",f?',':'+');cout<<i->first;f=F=1; }}if (f) printf("\n");f=0;for (i=a.begin();i!=a.end();i++){if (b.find(i->first)==b.end()){printf("%c",f?',':'-');cout<<i->first;f=F=1; }}if (f) printf("\n");f=0;for (i=b.begin();i!=b.end();i++){if (a.find(i->first)!=a.end())if (a[i->first]!=i->second){printf("%c",f?',':'*');cout<<i->first; f=F=1; }}if (f) printf("\n");if (!F) printf("No changes\n");printf("\n");}}
0 0
- CSU 1113 Updating a Dictionary
- CSU 1113 Updating a Dictionary
- CSU 1113 Updating a Dictionary
- CSU 1113 Updating a Dictionary (湖南省第八届大学生计算机程序设计竞赛)
- uva12504 Updating a Dictionary
- Updating a Dictionary
- 12504 - Updating a Dictionary
- 12504 - Updating a Dictionary
- UVA12504 - Updating a Dictionary
- 12504 - Updating a Dictionary
- UVA12504 Updating a dictionary
- UVA12504--Updating a Dictionary
- Updating a Dictionary
- UVA - 12504 Updating a Dictionary
- UVa 12504 - Updating a Dictionary
- 更新字典(Updating a Dictionary)
- UVA - 12504 Updating a Dictionary
- Uva - 12504 - Updating a Dictionary
- iOS开发 GPS定位 指定语言 返回中文地点
- 第8题
- Linux系统下关于用户和组的配置管理
- #pragma mark in Swift?
- Visual Studio 2010 C/C++连接mysql
- CSU 1113 Updating a Dictionary
- 清除安卓应用里多余的资源文件
- Java并发编程:Callable、Future和FutureTask
- 分享一个自己写的cnBeta客户端源码
- 1.8
- eclipse查看类的继承、实现关系快捷键
- 【一道不知道名字的题】AC自动机+dp
- 1.9
- Android组件ListView的适配器BaseAdapter