更新字典 (Updating a Dictionary,UVa12504)
题目描述:

解题思路:
1.根据:和,获得字符串
2.使用两个map进行比较;
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
map<string, string>::iterator it;
map<string,string> dict[];
string str[];
int main(int argc, char *argv[])
{
int t ;
cin >> t;
while(t--)
{
dict[].clear(), dict[].clear();
for(int i=;i<;i++)
{
string s,t1,t2;
cin >> s ;
int j=,len = s.size() ;
while(j < len && len > )
{
while(s[j]!=':') t1 += s[j++] ; ++j ;
while(s[j]!=',' && s[j]!='}') t2 += s[j++] ; ++j ;
dict[i][t1] = t2 ;
t1 = t2 = "" ;
}
}
int a=,s=,m=;
for(it=dict[].begin();it != dict[].end();it++)
if(!dict[].count(it->first)) str[a++] = it->first;
if(a)
{
sort(str,str+a);
cout << "+" << str[] ;
for(int i = ; i < a; ++i) cout << ',' << str[i];
puts("");
}
for(it=dict[].begin();it != dict[].end();it++)
if(!dict[].count(it->first)) str[s++] = it->first;
if(s)
{
sort(str,str+s);
cout << "-" << str[] ;
for(int i = ; i < s; ++i) cout << ',' << str[i];
puts("");
}
for(it=dict[].begin();it != dict[].end();it++)
if(dict[].count(it->first)&&dict[][it->first] != it->second) str[m++] = it->first;
if(m)
{
sort(str,str+m);
cout << "*" << str[] ;
for(int i = ; i < m; ++i) cout << ',' << str[i];
puts("");
}
if(!(a || s || m)) puts("No changes");
puts("");
}
return ;
}
更新字典 (Updating a Dictionary,UVa12504)的更多相关文章
- 湖南生第八届大学生程序设计大赛原题 C-Updating a Dictionary(UVA12504 - Updating a Dictionary)
UVA12504 - Updating a Dictionary 给出两个字符串,以相同的格式表示原字典和更新后的字典.要求找出新字典和旧字典的不同,以规定的格式输出. 算法操作: (1)处理旧字典, ...
- [刷题]算法竞赛入门经典(第2版) 5-11/UVa12504 - Updating a Dictionary
题意:对比新老字典的区别:内容多了.少了还是修改了. 代码:(Accepted,0.000s) //UVa12504 - Updating a Dictionary //#define _XieNao ...
- [ACM_模拟] UVA 12504 Updating a Dictionary [字符串处理 字典增加、减少、改变问题]
Updating a Dictionary In this problem, a dictionary is collection of key-value pairs, where keys ...
- Problem C Updating a Dictionary
Problem C Updating a Dictionary In this problem, a dictionary is collection of key-value pairs, ...
- 字典学习(Dictionary Learning, KSVD)详解
注:字典学习也是一种数据降维的方法,这里我用到SVD的知识,对SVD不太理解的地方,可以看看这篇博客:<SVD(奇异值分解)小结 >. 1.字典学习思想 字典学习的思想应该源来实际生活中的 ...
- 字典学习(Dictionary Learning)
0 - 背景 0.0 - 为什么需要字典学习? 这里引用这个博客的一段话,我觉得可以很好的解释这个问题. 回答这个问题实际上就是要回答“稀疏字典学习 ”中的字典是怎么来的.做一个比喻,句子是人类社会最 ...
- csuoj 1113: Updating a Dictionary
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 1113: Updating a Dictionary Time Limit: 1 Sec ...
- JavaScript中创建字典对象(dictionary)实例
这篇文章主要介绍了JavaScript中创建字典对象(dictionary)实例,本文直接给出了实现的源码,并给出了使用示例,需要的朋友可以参考下 对于JavaScript来说,其自身的Array对象 ...
- [Swift]LeetCode676. 实现一个魔法字典 | Implement Magic Dictionary
Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be ...
随机推荐
- Linux -- 用户篇
Linux -- 用户与用户组 1.Linux 系统中有三种角色:所有者(用户),用户组与其他人,一张图可以说明用户与用户组的关系. 如图,某公司相当于一个用户组,该用户组下有A,B两个用户,用户拥有 ...
- hdu Hat's Fibonacci(用了kuangbin模板)
大数的位数设置很坑,设成700会越界,设成800会超空间,最后设成了750居然就过了.... #include <iostream> #include <cstdio> #in ...
- Zookeeper -- 关于Zookeeper
Zookeeper是什么? 分布式协调框架 Zookeeper中文件呈树形结构,树形结构下包含多个节点,称为Znode:zk中节点存储数据不超过1M,指得是Znode中存储数据不超过1M Zookee ...
- Ubuntu12.04下zxing源码编译
1.下载zxing源码 git clone https://github.com/15903016222/zxing-cpp.git 2.安装依赖工具cmake sudo apt-get instal ...
- python+selenium实现自动抢票
使用说明 程序运行开始,需要输入出发地,目的地,出发时间,乘客信息,车次:乘客信息和车次可以输入多个 刚刚开始学习爬虫,selenium仅仅是解放了双手,运行效率不是很高: 程序运行时会打开chrom ...
- python基础 抽象类(接口类)
Python中没有接口.接口类,抽象类:定义 制定一个规范 #必须要导入from abc import ABCMeta,abstractmethod class Payment(metaclass = ...
- 用for循环求1-100的所有数的和
2.求1-100的所有数的和 x=0for y in range (1,101): x=x+yprint(x)#Python for循环中可以循环一个列表或者某一个字符串下面是for的基本格式,英文是 ...
- Python学习笔记六:集合
集合 Set,去重,关系测试:交.并.差等:无序 list_1=set(list_1), type(list_1) list_2=set([xxxxx]) 交集:list_1.intersectin( ...
- PHP连接MySql闪断自动重连的方法
使用php作为后台运行程序(例如短信群发),在cli模式下执行php,php需要连接mysql循环执行数据库处理. 当mysql连接闪断时,之后循环的执行将会失败. 我们需要设计一个方法,当mysql ...
- 观看杨老师(杨旭)Asp.Net Core MVC入门教程记录
观看杨老师(杨旭)Asp.Net Core MVC入门教程记录 ASP.NET Core MVC入门 Asp.Net Core启动和配置 Program类,Main方法 Startup类 依赖注入,I ...