这道题难度不大,主要是考察熟练运用C++的容器,字符串等操作。

  另外注意特殊情况是否需要特殊处理。即当一个字典为空时,无论另一个字典是否有值,输出的结果都为No Change,这点需要注意一下。

  另外,仔细阅读题目的输入输出部分,避免定势思维而误解题意,比如这题我还以为不用输出最后一个数据的空行,其实题目说的是每个数据后都有一空行。

 #include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <sstream>
using namespace std;
map<string,string> map1;
map<string,string> map2;
int main(){
int n;
string s,s3;
string dc(",:{}");
cin >> n;
while(n--){
string::size_type pos=;;
cin >> s;
set<string> set1;//+
set<string> set2;//-
set<string> set3;//*
map1.clear();
map1[","]=",";
while((pos=s.find_first_of(dc,pos))!=string::npos){
s.replace(pos,," ");
pos++;
}
string buf;
stringstream ss(s);
string s1,s2;
while(ss>>buf){
if(s1.empty())s1=buf;
else s2=buf;
if(!s2.empty()){
map1[s1]=s2;
s1=s2="";
}
}
/*
for(auto a : map1){
cout << a.first << " " << a.second <<endl;
}
*/
cin >> s3; map2.clear();
map2[","]=",";
pos=; while((pos=s3.find_first_of(dc,pos))!=string::npos){
s3.replace(pos,," ");
pos++;
}
stringstream ss1(s3);
s1=s2="";
while(ss1>>buf){
if(s1.empty())s1=buf;
else s2=buf;
if(!s2.empty()){
map2[s1]=s2;
s1=s2="";
}
}
/*
for(auto a : map2){
cout << a.first << " " << a.second <<endl;
}
*/
for(auto a : map1){
for(auto b : map2){
if(! map1[b.first].empty()){
if(map1[b.first]!=b.second){
//此处表示修改
set3.insert(b.first);
}
}
else {
set1.insert(b.first);
//表示新增
}
}
}
for(auto a : map2){
for(auto b : map1){
if(map2[b.first].empty())
{
set2.insert(b.first);
//表示新增
}
}
}
bool is_changed1=,is_changed2=,is_changed3=;
for(set<string>::iterator it = set1.begin();it!=set1.end();it++){
if((*it).empty())continue;
if(it!=set1.begin())cout << ",";
else cout << "+";
cout << *it;is_changed1=;
}
if(is_changed1)cout <<endl;
for(set<string>::iterator it = set2.begin();it!=set2.end();it++){
if((*it).empty())continue;
if(it!=set2.begin())cout << ",";
else cout << "-";
cout << *it;is_changed2=;
}
if(is_changed2)cout <<endl;
for(set<string>::iterator it = set3.begin();it!=set3.end();it++){
if((*it).empty())continue; if(it!=set3.begin())cout << ",";
else cout << "*";is_changed3=;
cout << *it;
}
if(is_changed3)cout <<endl;
if(is_changed1+is_changed2+is_changed3==)cout <<"No changes" <<endl; cout <<endl;
}
return ;
}

代码目前比较繁琐,日后再简化一下代码。

Uva12504 Updating a Dictonary的更多相关文章

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

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

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

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

  3. 更新字典 (Updating a Dictionary,UVa12504)

    题目描述: 解题思路: 1.根据:和,获得字符串 2.使用两个map进行比较: #include <iostream> #include <algorithm> #includ ...

  4. CocoaPods被卡住:Updating local specs repositories

    使用CocoaPods被卡住:Updating local specs repositories 使用 pod install --verbose --no-repo-update

  5. 使用CocoaPods被卡住:Updating local specs repositories

    使用cocoapods 更新第三库,一直停留在.Updating local specs repositories 后来查发现pod install  被墙了,请大家换成pod install --v ...

  6. MySQL提示:The server quit without updating PID file问题的解决办法(转载)

    MySQL提示:The server quit without updating PID file问题的解决办法 今天网站web页面提交内容到数据库,发现出错了,一直提交不了,数找了下原因,发现数据写 ...

  7. Mysql 启动错误:the server quit without updating pid

    接到任务看看mysql为啥起不来,就上服务器上看了看,确实起不来,至于之前发生了啥也不知道. 服务器Ubuntu,mysql-5.6 1.先试下mysql登陆 mysql -uroot -p 发现报错 ...

  8. lnmp下启动mysql报错 The server quit without updating PID file

    启动时候错误代码:Starting MySQL[FAIL.] The server quit without updating PID file (/var/run/mysqld/mysqld.pid ...

  9. MySQL数据库出现The server quit without updating PID file.

    一.服务器环境 操作系统:CentOS-6.4 服务器环境:集成环境LNMP1.0 二.步骤重现 1.安装LNMP1.0,具体操作方法见这里,安装成功: 2.因个人需求,现将MySQL数据库存放在/d ...

随机推荐

  1. redis在windows上的安装

    1.下载地址:https://github.com/MSOpenTech/redis 主要支持win64的,有个msi文件可以直接安装,安装后redis会变成一个服务,对于windows来说这种最方便 ...

  2. [kuangbin带你飞]专题十一 网络流

            ID Origin Title   34 / 81 Problem A POJ 3436 ACM Computer Factory   92 / 195 Problem B POJ 3 ...

  3. [SQL]SQL语言入门级教材_SQL数据操作基础(二)

    SQL数据操作基础(初级) netnova 于 -- :: 加贴在 数据库探讨: 为了建立交互站点,你需要使用数据库来存储来自访问者的信息.例如,你要建立一个职业介绍服务的站点,你就需要存储诸如个人简 ...

  4. Oracle数据库——常用命令(用户管理、数据库导入导出)

    --==cmd控制台==-- --==日常用户管理SQL==-- --连接到SQLPLUS >sqlplus /nolog --以dba身份连接 sql>conn / as sysdba ...

  5. Redis附加功能之Redis流水线pipeline

    流水线功能的目的:通过减少客户端与服务器之间的通信次数来提高程序的执行效率. 一.通信 在一般情况下, 用户每执行一个 Redis 命令,客户端与服务器都需要进行一次通信:客户端会将命令请求发送给服务 ...

  6. POJ 1088 滑雪 记忆化DP

    滑雪 Time Limit: 1000MS   Memory Limit: 65536K       Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度 ...

  7. 图论Hrbust1708许可证

    http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1708 #include<st ...

  8. Android中MenuInflater实例

    我们知道,LayoutInflater是用来实例化整个布局文件,而MenuInflater是用来实例化Menu目录下的Menu布局文件的. 传统意义上的菜单定义需要Override Activity的 ...

  9. Quartz.Net CronExpression表达式详解

    Quartz.Net是我们常用的开源任务调度程序,其中最方便最强大的功能就是灵活多变的定时任务执行的支持.他靠什么来实现这个灵活的任务定时调度呢,就是咱们今天要详细分享的Cron Express表达式 ...

  10. 一目了然c++虚基类!

    #include <IOSTREAM.H> //基类 class CBase ...{ protected: int a; public: CBase(int na) ...{ a=na; ...