【习题 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 ...
随机推荐
- 关于字符串math函数的用法例子
var objStr=new String("Yue I love you till the end of my life!"); var reg3 = /[^\s+]/g; ob ...
- MATLAB —— 编程基础
字符串 abs —— 输出字符串ascii码 strvcat —— 把多个字符串横向连接成长字符串 fprintf —— 把格式化的文本写到文件中或显示屏上 int2str —— 整数转换成字符串 n ...
- HDU 2564 饭卡
饭卡 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- CMDB学习之四 ——DEBUG模式
定义一个debug,进行解析调试,到测试文件 配置文件,配置debug模式,定义环境变量, #!/usr/bin/env python # -*- coding:utf-8 -*- import os ...
- php 根据html table生成excel文件
<?php /* *处理Excel导出 *@param $datas array 设置表格数据 *@param $titlename string 设置head *@param $title s ...
- Oracle学习总结(8)—— 面向程序员的数据库访问性能优化法则
特别说明: 1. 本文只是面对数据库应用开发的程序员,不适合专业DBA,DBA在数据库性能优化方面需要了解更多的知识: 2. 本文许多示例及概念是基于Oracle数据库描述,对于其它关系型数据库也 ...
- NYOJ_75 日期计算 (推断这一天是这一年中的第几天)
题目地址 如题,输入一个日期,格式如:2010 10 24 ,推断这一天是这一年中的第几天. 分析: 官方给的最优答案用了for 和switch语句结合,十分巧妙. 代码 /* 如题,输入一个日期 ...
- RecyclerView具体解释
public class RecyclerView extends ViewGroup implements ScrollingView, NestedScrollingChild { 由上面的继承结 ...
- Qt 5.11的QChar、QString、QTextBoundaryFinder和双向文本算法现在完全兼容Unicode 10
本文翻译自:Qt 5.11 released 原文作者: Qt公司CTO兼Qt开源项目维护官Lars Knoll翻译校审:Richard.Hongfei.Haipeng 5月22日,我们提发布了Qt ...
- Web页面转换成Word文件,利用wordXML
简介:处理流程表单数据以WordXML形式填充Word文档表格换行符丢失问题 //将前台收集的XML中“$”循环拆分成"<w:br/>" by pengyc 解决表格填 ...