http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113

1113: Updating a Dictionary

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 491  Solved: 121
[Submit][Status][Web Board]

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

HINT

Source

湖南省第八届大学生计算机程序设计竞赛

分析:

STL容器的使用。

AC代码:

 #include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include <cctype>
#include<map>
using namespace std;
char s1[];
char s2[];
char s3[];
char s4[];
bool cmp(string ss,string sss)
{
return ss<sss;
}
string st,ed;
int main()
{
int T,t1,t2;
scanf("%d",&T);
gets(s1);
while(T--)
{ map<string,string>ss1;
map<string,string>ss2;
map<string,string>::iterator it;
string ss[];
string plu[],dir[],key[];
int k1 = ,k2 =,k3 =,k4=;
ss1.clear();
ss2.clear();
for(int i=;i<;i++)
{
ss[i].clear();
plu[i].clear();
dir[i].clear();
key[i].clear();
}
gets(s1);
gets(s2);
st = ed = "";
int len1 = strlen(s1);
int len2 = strlen(s2);
for(int i=;i<len1;i++)
{
if(isdigit(s1[i]))
ed = ed+s1[i];
else if(isalpha(s1[i]))
st = st+s1[i];
else if(s1[i] == ',')
{
ss1[st] =ed;
ss[k4++] = st;
st = ed = "";
}
else if(s1[i] == '}')
{
if(st!="")
{
ss[k4++] = st;
ss1[st] =ed;
}
st = ed = "";
}
}
for(int i=;i<len2;i++)
{
if(isdigit(s2[i]))
ed =ed+s2[i];
else if(isalpha(s2[i]))
st = st+s2[i];
else if(s2[i] == ',')
{
it = ss1.find(st);
if(it!=ss1.end())//如果找到
{
if(ss1[st] != ed)//增加的
key[k3++] = st;
}
else
{
plu[k1++] = st;
}
ss2[st] =ed;
st = ed = "";
}
else if(s2[i] == '}')
{
if(st!="")
{
it = ss1.find(st);
if(it!=ss1.end())//如果找到
{
if(ss1[st] != ed)//增加的
key[k3++] = st;
}
else
{
plu[k1++] = st;
}
ss2[st] =ed;
}
st = ed = "";
}
}
for(int i=;i<k4;i++)
{
it = ss2.find(ss[i]);
if(it == ss2.end())//如果没有找到
{
dir[k2++] = ss[i];
}
}
if(k1+k2+k3 == )
printf("No changes\n");
else
{
sort(plu,plu+k1,cmp);
for(int i=;i<k1;i++)
{
if(i==) printf("+%s",plu[i].c_str());
else printf(",%s",plu[i].c_str());
}
if(k1>) printf("\n"); sort(dir,dir+k2,cmp);
for(int i=;i<k2;i++)
{
if(i==) printf("-%s",dir[i].c_str());
else printf(",%s",dir[i].c_str());
}
if(k2>) printf("\n"); sort(key,key+k3,cmp);
for(int i=;i<k3;i++)
{
if(i==) printf("*%s",key[i].c_str());
else printf(",%s",key[i].c_str());
}
if(k3>) printf("\n"); }
printf("\n");
}
return ;
}

csuoj 1113: Updating a Dictionary的更多相关文章

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

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

  2. CSU 1113 Updating a Dictionary

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

  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. 介绍UDF,以及完成大小写的转换

    一:概述 1.UDF 用户自定义函数,用java实现自定义的需求 2.UDF的类型 udf:一进一出 udaf:多进一出 udtf:一进多出 3.udf的实现步骤 继承UDF类 实现evaluate的 ...

  2. sort,ksort,asort的区别

    sort--对数组的val进行排序 ksort--对数组的key值进行排序 asort--对数组进行排序,键与值的对应关系不变 1.sort对数组排序 格式如下:bool sort(array &am ...

  3. Object的属性property详细解释(自动生成成员变量)

    类Class中的属性property: 在ios第一版中,我们为输出口同时声明了属性和底层实例变量,那时,属性是oc语言的一个新的机制,并且要求你必须声明与之对应的实例变量,例如: @interfac ...

  4. 常用yum命令

    yum list 查询所有可用软件包 yum search 关键字 查询和关键字相关的包 yum -y install 包名 加上-y自动回答yes yum -y update 包名 升级  yum ...

  5. ArcGIS中添加进自定义的ttf字符标记符号

    原文:ArcGIS中添加进自定义的ttf字符标记符号 ArcGIS系统中的样式可能不能满足实际生产需要,为了实现快速制图,可自定义一些样式,以便重复利用. 1.   制作的符号库 使用 FontCre ...

  6. Introduction to Face Detection and Face Recognition

    http://www.shervinemami.info/faceRecognition.html http://docs.opencv.org/2.4/modules/contrib/doc/fac ...

  7. 微信支付开发(1) 微信支付URL配置

    由于微信支付接口更新,本文档已过期,请查看新版微信支付教程.地址 http://www.cnblogs.com/txw1958/category/624506.html 本文介绍微信支付申请时如何设置 ...

  8. Spring中的工厂模式和单例模式

    Spring预备知识(适合中小型项目) 作用:集成和管理其他框架 工厂模式: A  a  = new A( ); 将类所要创建的对象写入工厂,统一进行管理 package com.spring; pu ...

  9. jQuery操作控件

    在项目中添加前台控件radio,操作两个div的显示和隐藏,其实是一个很简单的问题,但是费了老大劲才完成,也就是jQuery操作控件的一些基础知识.方法有三种,简单介绍: 1.给元素设置style属性 ...

  10. 一网打尽当下NoSQL类型、适用场景及使用公司

    在过去几年,关系型数据库一直是数据持久化的唯一选择,数据工作者考虑的也只是在这些传统数据库中做筛选,比如SQL Server.Oracle或者是MySQL.甚至是做一些默认的选择,比如使用.NET的一 ...