博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[ACM_模拟] UVA 12504 Updating a Dictionary [字符串处理 字典增加、减少、改变问题]
阅读量:6237 次
发布时间:2019-06-22

本文共 2960 字,大约阅读时间需要 9 分钟。

 

 

  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 (   T$ \le$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 题目大意:每次给2个字符串,字符串里的内容表示为key:value对,顺序随意,比较2个字符串里的内容判断增加了那些,减少了那些,key值对应的value变了的有哪些。水题,字符串处理,烦!
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
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 0;//no change 16 else return 1;//change 17 } 18 else{ //not same 19 if(key
=0;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[101],x2[101]; 51 int i=0; 52 while(in1>>key>>value){ 53 x1[i++].set(key,value); 54 } 55 int j=0; 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[101];int add_num=0; 62 string sub[101];int sub_num=0; 63 string cha[101];int cha_num=0; 64 int ii=0,jj=0; 65 while(ii

 

转载地址:http://rvzia.baihongyu.com/

你可能感兴趣的文章
不同网络层的协议与工具
查看>>
sass,compass让开发效率飞起
查看>>
mac效率工具
查看>>
unity 发布.exe的相关设置
查看>>
android icon设计规则
查看>>
Excel 返回第2大的值
查看>>
1576 最长严格上升子序列
查看>>
LINUX GBK->UTF-8文件编码批量转换脚本[转]
查看>>
01数据挖掘引言
查看>>
Oracle 10g 下载地址
查看>>
RMAN_学习实验1_RMAN备份标准过程(案例)
查看>>
linux内核分析作业6:分析Linux内核创建一个新进程的过程
查看>>
《Linux内核设计与实现》读书笔记 第四章 进程调度
查看>>
距离和相似度量
查看>>
iOS方法类:CGAffineTransform的使用大概
查看>>
mybatis逆向工程之生成文件解释
查看>>
hadoop mapreduce中对splite的处理
查看>>
我的第三篇博客(激动激动真激动!!!)A-B Problem
查看>>
C/C++二维数组名和二级指针
查看>>
jsf
查看>>