【习题 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 ...
随机推荐
- LuoguP2754 [CTSC1999]家园(分层图,最大流)
题目背景 none! 题目描述 由于人类对自然资源的消耗,人们意识到大约在 2300 年之后,地球就不能再居住了.于是在月球上建立了新的绿地,以便在需要时移民.令人意想不到的是,2177 年冬由于未知 ...
- 【DRF频率】
目录 使用自带的频率限制类 使用自定义的频率限制类 开发平台的API接口调用需要限制其频率,以节约服务器资源和避免恶意的频繁调用. DRF就为我们提供了一些频率限制的方法. DRF中的版本.认证.权限 ...
- 【习题 8-3 UVA - 12545】Bits Equalizer
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果1的个数第一个串比第2个串多. 那么就无解. 否则. 找几个位置去凑1 优先找'?'然后才是0的位置 剩余的全都用swap操作就 ...
- Java数据传递实验
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 在开发过程中,我们经常会遇到对象传递的问题,有时仅仅传递数据,有时却要实现数据同步:这时,就要分清两 ...
- android基于开源网络框架asychhttpclient,二次封装为通用网络请求组件
网络请求是全部App都不可缺少的功能,假设每次开发都重写一次网络请求或者将曾经的代码拷贝到新的App中,不是非常合理,出于此目的,我希望将整个网络请求框架独立出来,与业务逻辑分隔开,这样就能够避免每次 ...
- Tuple<int, int> Dictionary<string, object>妙用
Tuple<int, int> Dictionary<string, object>妙用
- WebService 的Description 属性说明(转)
转自:http://exception.thinksaas.cn/0/173/173623.html 在WebMethod的description 中可使用超文本, 举例: 如上图中,红框类的WebS ...
- BZOJ1195: [HNOI2006]最短母串(Trie图,搜索)
Description 给定n个字符串(S1,S2,„,Sn),要求找到一个最短的字符串T,使得这n个字符串(S1,S2,„,Sn)都是T的子串. Input 第一行是一个正整数n(n<=12) ...
- Vue+TypeScript学习
Vue CLI 内置了 TypeScript 工具支持.在 Vue 的下一个大版本 (3.x) 中也计划了相当多的 TypeScript 支持改进,包括内置的基于 class 的组件 API 和 TS ...
- 洛谷 P1130 红牌
P1130 红牌 题目描述 某地临时居民想获得长期居住权就必须申请拿到红牌.获得红牌的过程是相当复杂 ,一共包括N个步骤.每一步骤都由政府的某个工作人员负责检查你所提交的材料是否符合条件.为了加快进程 ...