湖南省第八届大学生程序设计大赛原题 C

C - Updating a Dictionary

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

Submit Status Practice CSU 1113

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 

题意:给你两本字典,找两本字典的不同。一个模拟题,注意,两本字典都有可能是空字典,这里被坑了,再次看题发现了坑点。如果第一本字典没有,而第二本字典里面有,输出+然后输出第二本字典里面有而第一本字典没有的。如果第二本字典没有,而第一本字典里面有,输入-然后输出第一本字典里面有而第二本字典没有的。如果第一本字典有并且第二本字典有,但是后面的数字不一样,那么输出*然后输出页码不同的字。如果两本字典完全一样,输出No changes注意,每组案例输出后要有空行!分析:就是无脑的模拟,不解释也能看懂的
#include <iostream>
#include <string>
#include <map>
using namespace std;

map<string,string>s1;
map<string,string>s2;
map<string,string>::iterator it;

string aa[105];

void print(char c,int n)
{
    cout<<c<<aa[0];
    for(int i=1;i<n;i++)
    {
        cout<<","<<aa[i];
    }
    cout<<endl;
}

int main()
{
    string str1;
    string str2;
    int T;
    cin>>T;
    while(T--)
    {
        s1.clear();
        s2.clear();
        cin>>str1;
        int n=str1.size();
        cin>>str2;
        int m=str2.size();
        string a,b;
        for(int i=1;i<n;)
        {
            a="";
            while(str1[i]!=‘:‘&&str1[i]!=‘}‘)
                a+=str1[i++];
            if(str1[i]==‘}‘)
                break;
            i++;
            b="";
            while(str1[i]!=‘,‘&&str1[i]!=‘}‘)
                b+=str1[i++];
            s1[a]=b;
            i++;
        }
        for(int i=1;i<m;)
        {
            a="";
            while(str2[i]!=‘:‘&&str2[i]!=‘}‘)
                a+=str2[i++];
            if(str2[i]==‘}‘)
                break;
            i++;
            b="";
            while(str2[i]!=‘,‘&&str2[i]!=‘}‘)
                b+=str2[i++];
            s2[a]=b;
            i++;
        }
        int c1=0,c2=0,c3=0;
        for(it=s2.begin();it!=s2.end();it++)
        {

            if(!s1.count(it->first))
                aa[c1++]=it->first;
        }
        if(c1)
            print(‘+‘,c1);
        for(it=s1.begin();it!=s1.end();it++)
        {

            if(!s2.count(it->first))
               aa[c2++]=it->first;
        }
        if(c2)
            print(‘-‘,c2);
        for(it=s2.begin();it!=s2.end();it++)
        {
            if(s1.count(it->first)&&s1[it->first]!=it->second)
               aa[c3++]=it->first;
        }
        if(c3)
            print(‘*‘,c3);
        if(c1+c2+c3==0)
            cout<<"No changes"<<endl;
        cout<<endl;
    }
    return 0;
}
时间: 2024-08-02 10:55:16

湖南省第八届大学生程序设计大赛原题 C的相关文章

湖南省第八届大学生程序设计大赛原题 J

J - 病毒 Time Limit:3000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Submit Status Practice CSU 1120 Description 你有一个日志文件,里面记录着各种系统事件的详细信息.自然的,事件的时间戳按照严格递增顺序排列(不会有两个事件在完全相同的时刻发生). 遗憾的是,你的系统被病毒感染了,日志文件中混入了病毒生成的随机伪事件(但真实事件的相对顺序保持不变).备份的日志

湖南省第八届大学生程序设计大赛原题 E

E - 最短的名字 Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice CSU 1115 Description 在一个奇怪的村子中,很多人的名字都很长,比如aaaaa, bbb and abababab. 名 字这么长,叫全名显然起来很不方便.所以村民之间一般只叫名字的前缀.比如叫'aaaaa'的时候可以只叫'aaa',因为没有第二个人名字的前三个字母

湖南省第八届大学生程序设计大赛原题 B

B - 机器人的指令 Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Submit Status Practice CSU 1112 Description 数轴原点有一个机器人.该机器人将执行一系列指令,你的任务是预测所有指令执行完毕之后它的位置. ·LEFT:往左移动一个单位 ·RIGHT: 往右移动一个单位 ·SAME AS i: 和第i 条执行相同的动作.输入保证i 是一个正整数,且不

湖南省第八届大学生程序设计大赛原题 A

A - 三家人 Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Submit Status Practice CSU 1111 Description 有 三户人家共拥有一座花园,每户人家的太太均需帮忙整理花园.A 太太工作了5 天,B 太太则工作了4 天,才将花园整理完毕.C 太太因为正身怀六甲无法加入她们的行列,便出了90元.请问这笔钱如何分给A.B 二位太太较为恰当?A 应得多少元?90

UVA 12505 湖南省第八届大学生程序设计大赛原题 D - 平方根大搜索

D - 平方根大搜索 Time Limit:5000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Submit Status Practice CSU 1114 Description 在二进制中,2的算术平方根,即sqrt(2),是一个无限小数1.0110101000001001111... 给定一个整数n和一个01串S,你的任务是在sqrt(n)的小数部分(即小数点之后的部分)中找到S第一次出现的位置.如果sqrt(

最简单的问题(重庆市第八届大学生程序设计大赛D) (线段树+离线思想)

考场上的时候直接一脸懵逼了,啥? 区间里面又要求子区间,还TM有上下界? 略加思索后倒是发现没有那么麻烦,因为很容易得出如下结论: 1.对于一个满足条件的区间[L , R],对于他所有的子区间显然也满足条件. 2.一个区间[L , R]的子区间数量(包括自己)为(R-L+1)*(R-L+2)/2 证:因为区间都是连续的,所以显然该区间含有R-L+1个长度为1的子区间,R-L个长度为2的子区间,R-L-1个长度为3的子区间......1个长度为R-L+1的子区间 然后根据等差数列求和公式 Sn =

山东省第一届ACM大学生程序设计竞赛(原题) 回顾 4.18

Phone Number 题目链接:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2151&cid=1172 题意很简单:给出N行电话号码,寻找有没有一串是另一串的前缀,有的话输出No,当然两个一样的也是No 题解:没有前缀0,直接用二维数组存,大循环就行了,用strcmp比较相等.不会超时. Hello World!     题目链接:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=215

CSU OJ 1120 病毒(湖南省第八届大学生计算机程序设计竞赛)

 1120: 病毒 Time Limit: 3 Sec  Memory Limit: 128 MB Submit: 146  Solved: 53 [Submit][Status][Web Board] Description 你有一个日志文件,里面记录着各种系统事件的详细信息.自然的,事件的时间戳按照严格递增顺序排列(不会有两个事件在完全相同的时刻发生). 遗憾的是,你的系统被病毒感染了,日志文件中混入了病毒生成的随机伪事件(但真实事件的相对顺序保持不变).备份的日志文件也被感染了,但由于

CSU OJ 1115 最短的名字(字典树——湖南省第八届大学生计算机程序设计竞赛)

 1115: 最短的名字 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 141  Solved: 56 [Submit][Status][Web Board] Description 在一个奇怪的村子中,很多人的名字都很长,比如aaaaa, bbb and abababab. 名字这么长,叫全名显然起来很不方便.所以村民之间一般只叫名字的前缀.比如叫'aaaaa'的时候可以只叫'aaa',因为没有第二个人名字的前三个字母是'aaa'.不过你不能