【习题 5-11 UVA 12504 】Updating a Dictionary
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
不确定某个map里面是否有某个关键字的时候。
要用find来确定。
如果直接用访问下标的形式去做的话。
会强行给他加一个那个关键字(原来没有).
(当然那个关键字的映射为空就是了);
【代码】
#include <bits/stdc++.h>
using namespace std;
string s;
map<string, string> mmap1, mmap2;
vector <string> v[3];
void getmap(map<string, string> &mmap, string s)
{
int len = s.size();
for (int i = 0; i < len; i++)
if (s[i] == '{' || s[i] == ':' || s[i] == ',' || s[i] == '}')
s[i] = ' ';
string a, b;
stringstream ss(s);
while (ss >> a >> b)
{
mmap[a] = b;
}
}
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
int unused;
cin >> unused;
while (unused--)
{
for (int i = 0; i < 3; i++)v[i].clear();
mmap1.clear(); mmap2.clear();
cin >> s;
getmap(mmap1, s);
cin >> s;
getmap(mmap2, s);
for (auto temp : mmap2)
if (mmap1.find(temp.first)==mmap1.end()) v[0].push_back(temp.first);
for (auto temp : mmap1)
if (mmap2.find(temp.first)==mmap2.end()) v[1].push_back(temp.first);
for (auto temp : mmap1)
if (mmap2.find(temp.first)!=mmap2.end() && mmap2[temp.first] != temp.second)
{
string s1 = temp.second, s2 = mmap2[temp.first];
v[2].push_back(temp.first);
}
bool ok = v[0].empty() && v[1].empty() && v[2].empty();
if (ok) cout << "No changes" << endl;
else
{
for (int i = 0; i < 3; i++)
if (!v[i].empty())
{
if (i == 0) cout << '+';
if (i == 1) cout << '-';
if (i == 2) cout << '*';
cout << v[i][0];
for (int j = 1; j < (int)v[i].size(); j++)
cout << "," << v[i][j];
cout << endl;
}
}
cout << endl;
}
return 0;
}
【习题 5-11 UVA 12504 】Updating a Dictionary的更多相关文章
- [ACM_模拟] UVA 12504 Updating a Dictionary [字符串处理 字典增加、减少、改变问题]
Updating a Dictionary In this problem, a dictionary is collection of key-value pairs, where keys ...
- Uva - 12504 - Updating a Dictionary
全是字符串相关处理,截取长度等相关操作的练习 AC代码: #include <iostream> #include <cstdio> #include <cstdlib& ...
- 【UVA】12504 Updating a Dictionary(STL)
题目 题目 分析 第一次用stringstream,真TMD的好用 代码 #include <bits/stdc++.h> using namespace std; int ...
- Uva 511 Updating a Dictionary
大致题意:用{ key:value, key:value, key:value }的形式表示一个字典key表示建,在一个字典内没有重复,value则可能重复 题目输入两个字典,如{a:3,b:4,c: ...
- csuoj 1113: Updating a Dictionary
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 1113: Updating a Dictionary Time Limit: 1 Sec ...
- 湖南生第八届大学生程序设计大赛原题 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 ...
- Problem C Updating a Dictionary
Problem C Updating a Dictionary In this problem, a dictionary is collection of key-value pairs, ...
- Updating a Dictionary UVA - 12504
In this problem, a dictionary is collection of key-value pairs, where keys are lower-case letters, a ...
随机推荐
- C#结构函数
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 缓存函数memorize
function mulity(x){ return x*x; } function memorize(f){ var cache = {}; var key = arguments.length + ...
- pix格式的摸索(二)
作者:朱金灿 来源:http://blog.csdn.net/clever101 PCI的系统格式pix是一个设计很巧妙的遥感图像格式,而且其设计巧妙之处不止一处两处,这些都有待我日后一一去摸索.今天 ...
- Linux LiveCD 诞生记
Linux LiveCD 诞生记 650) this.width=650;" onclick='window.open("http://blog.51cto.com/viewpic ...
- 一款开源Office软件---Lotus Symphony在Linux系统下的应用
点击下载观看试用录像 Linux系统下的办公软件有OpenOffice.永中Office.红旗Red Office.金山Wps Office及StarOffice等,今天我为大家介绍IBM推进军O ...
- linux环境下禅道搭建
1.下载禅道安装包,根据操作系统的版本: 2.上传包到linux的opt目录中: 3.解压包: cd /opt tar xzvf 禅道包名称,如:tar xzvf ZenTaoPMS.8.1.3.zb ...
- private SortedDictionary<string, object> Dic_values = new SortedDictionary<string, object>();
private SortedDictionary<string, object> Dic_values = new SortedDictionary<string, object&g ...
- DbSet<>.Find()
第一篇为大家带来新的API,DbSet<>.Find(). 过去我们常常用Where或First(FirstOrDefault)方法来查找对应的实体,比如: var people = fr ...
- WinForm无边框窗体移动方法
C#WinForm无边框窗体移动方法.模仿鼠标单击标题栏移动窗体位置 这里介绍俩种办法 方法一:直接通过修改窗体位置从而达到移动窗体的效果 方法二:直接伪装发送单击任务栏消息,让应用程序误以为单击任务 ...
- Ueditor 七牛集成
UEDITOR修改成功的 http://blog.csdn.net/uikoo9/article/details/41844747 http://blog.csdn.net/u010717403/ar ...