这道题难度不大,主要是考察熟练运用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. jquery mobile导致无法修改textarea的高度

    在引用了jquery mobile的js库和样式的页面中,添加textarea标签,会导致无法调整其height属性,不管是用CSS还是JS,最终都会被替换成height=52px 解决办法:在页面中 ...

  2. 九度OJ1468

    这道题其实就是个很简单的静态链表,需要注意的是,地址一共有5位,最后输出的时候如果之前是使用int类型存储地址的话,一定要强制规定输出的位数(5位),否则有可能会将高位省略.(如地址00001输出为1 ...

  3. Mingyang.net:hibernate.hbm2ddl.auto配置详解【转】

    原文地址:http://www.cnblogs.com/feilong3540717/archive/2011/12/19/2293038.html hibernate.cfg.xml 中hibern ...

  4. (转)Log4net 配置类库

    原文地址:http://blog.csdn.net/pfe_nova/article/details/20072137 1.单文件日志 对于单文件的日志,封装代码如下: public enum Log ...

  5. SQL语句在OLAP的妙用(多维分析与指标计算)

    ================================================================================ BI传统实现原理: 1.涉及维度管理( ...

  6. 通过srvctl add命令添加database信息到srvctl管理器-转

    这是我在实际中遇到的一个问题,rac+dg架构将备库切为主库,srvctl管理器中没有database信息. 对于dbca创建的数据库,srvctl中包含了数据库和实例的信息.但是对于备份恢复的RAC ...

  7. 在RAC中,当私有网线拔了后,会怎么样?

    原文链接http://blog.mchz.com.cn/?p=4305 实际环境: OS:oel5.5_x64 ORACLE:10205 3节点rac 架设于vmware esxi虚拟机上 所需测试项 ...

  8. Java-convert between INT and STRING

    int -> String 三种写法 String s = 43 + ""; String s = String.valueOf(43); String s = Intege ...

  9. 1738 - TWO NODES

    1738 - TWO NODES 时间限制: 10000 MS 内存限制: 65535 KB 问题描述 Suppose that G is an undirected graph, and the v ...

  10. Cocos2dx3.0过渡篇 各种遍历与范围for语句的使用【转】

    1.CCArray的遍历看到这里,有些人又按耐不住的要举起西瓜刀了:你不是说3.0beta后已经没有CCArray这货了吗?现在又拿出来作甚?其实我也很无辜,CCArray确实是没了,但在某个不为人知 ...