这道题难度不大,主要是考察熟练运用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. [ActionScript 3.0] AS3 绘制立方体

    package { import flash.display.Sprite; import flash.events.Event; import flash.geom.Vector3D; import ...

  2. AngularJs编写指令

    <!DOCTYPE html> <html ng-app="app"> <head lang="en"> <meta ...

  3. C Primer Plus(第五版)3

    第三章 数据和 C 在本章中你将学习下列内容: 1. 关键字: int, short, long, unsigned, char, float, double, _Bool, _Complex, _I ...

  4. POJ 2396 Budget【网络流】

    题意: cas           //测试数据组数 n m         //行数 列数 a1 a2 ... an    //每行的和 b1 b2 ... bn   //每列的和 q       ...

  5. poj 2253 Frogger dijkstra算法实现

    点击打开链接 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21653   Accepted: 7042 D ...

  6. PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数

    fread().fgets().fgetc().file_get_contents() 与 file() 函数用于从文件中读取内容. fread() fread() 函数用于读取文件(可安全用于二进制 ...

  7. ASP.NET5 中静态文件的各种使用方式

    所谓静态文件,包含HTML文件,css文件.图片文件和js文件等,他们是服务器直接读取到客户端的一些资源,在这篇文章中,我们将解释关于ASP.NET5和静态文件的一些内容. 服务端的静态文件 默认情况 ...

  8. [AFUI]App Framework Quickstart

    ---------------------------------------------------------------------------------------------------- ...

  9. multi2sim,booksim简介

    booksim是周期精确互连网络仿真器,设计用来配合"Principles and Practices of Interconnection Networks"课程教学,仿真器采用 ...

  10. html实体字符

    在html中,某些字符时预留的,如小于号(<).大于号(>),浏览器会认为它们是标签:有些字符无法用键盘输入.如果需要正确的显示它们,就需要在html源码中使用字符实体. 字符实体有实体名 ...