[刷题]算法竞赛入门经典(第2版) 5-11/UVa12504 - Updating a Dictionary
题意:对比新老字典的区别:内容多了、少了还是修改了。
代码:(Accepted,0.000s)
//UVa12504 - Updating a Dictionary
//#define _XieNaoban_
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<map>
using namespace std;
int T;
int main()
{
#ifdef _XieNaoban_
freopen("in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin >> T;
cin.ignore();
while (T--) {
map<string, string> dic;
for (int i(0);i < 2;++i) {
string line, key, value;
getline(cin, line);
for (auto &r : line)
if (r == ',' || r == ':' || r == '{' || r == '}') r = ' ';
istringstream in(line);
while (in >> key) {
in >> value;
if (i) {
auto d(dic.find(key));
if (d != dic.end()) {
if (d->second != value) d->second = "*";//changed
else d->second = '&';//not changed
}
else dic[key] = "+";//increased
}
else dic[key] = value;
}
}
vector<string> inc, rmv, chg;
for (const auto& r : dic)
switch (r.second[0])
{
case '+': inc.push_back(r.first);break;
case '*': chg.push_back(r.first);break;
case '&': break;
default: rmv.push_back(r.first);break;
}
if (inc.empty() && rmv.empty() && chg.empty())
cout << "No changes\n";
else {
if (!inc.empty()) {
cout << '+' << inc[0];
for (auto i(inc.begin() + 1);i != inc.end();++i)
cout << ',' << *i;
cout << '\n';
}
if (!rmv.empty()) {
cout << '-' << rmv[0];
for (auto i(rmv.begin() + 1);i != rmv.end();++i)
cout << ',' << *i;
cout << '\n';
}
if (!chg.empty()) {
cout << '*' << chg[0];
for (auto i(chg.begin() + 1);i != chg.end();++i)
cout << ',' << *i;
cout << '\n';
}
}
cout << '\n';
}
return 0;
}
分析:这题很水,轻松AC,没啥好说的。
[刷题]算法竞赛入门经典(第2版) 5-11/UVa12504 - Updating a Dictionary的更多相关文章
- [刷题]算法竞赛入门经典(第2版) 4-6/UVa508 - Morse Mismatches
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,10 ms) //UVa508 - Morse Mismatches #include< ...
- [刷题]算法竞赛入门经典(第2版) 5-15/UVa12333 - Revenge of Fibonacci
题意:在前100000个Fibonacci(以下简称F)数字里,能否在这100000个F里找出以某些数字作为开头的F.要求找出下标最小的.没找到输出-1. 代码:(Accepted,0.250s) / ...
- [刷题]算法竞赛入门经典(第2版) 5-13/UVa822 - Queue and A
题意:模拟客服MM,一共有N种话题,每个客服MM支持处理其中的i个(i < N),处理的话题还有优先级.为了简化流程方便出题,设每个话题都是每隔m分钟来咨询一次.现知道每个话题前来咨询的时间.间 ...
- [刷题]算法竞赛入门经典(第2版) 4-5/UVa1590 - IP Networks
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa1590 - IP Networks #include<iost ...
- [刷题]算法竞赛入门经典(第2版) 6-7/UVa804 - Petri Net Simulation
题意:模拟Petri网的执行.虽然没听说过Petri网,但是题目描述的很清晰. 代码:(Accepted,0.210s) //UVa804 - Petri Net Simulation //Accep ...
- [刷题]算法竞赛入门经典(第2版) 6-6/UVa12166 - Equilibrium Mobile
题意:二叉树代表使得平衡天平,修改最少值使之平衡. 代码:(Accepted,0.030s) //UVa12166 - Equilibrium Mobile //Accepted 0.030s //# ...
- [刷题]算法竞赛入门经典(第2版) 6-1/UVa673 6-2/UVa712 6-3/UVa536
这三题比较简单,只放代码了. 题目:6-1 UVa673 - Parentheses Balance //UVa673 - Parentheses Balance //Accepted 0.000s ...
- [刷题]算法竞赛入门经典(第2版) 5-16/UVa212 - Use of Hospital Facilities
题意:模拟患者做手术. 其条件为:医院有Nop个手术室.准备手术室要Mop分钟,另有Nre个恢复用的床.准备每张床要Mre分钟,早上Ts点整医院开张,从手术室手术完毕转移到回复床要Mtr分钟.现在医院 ...
- [刷题]算法竞赛入门经典(第2版) 5-10/UVa1597 - Searching the Web
题意:不难理解,照搬题意的解法. 代码:(Accepted,0.190s) //UVa1597 - Searching the Web //#define _XIENAOBAN_ #include&l ...
随机推荐
- 为什么你应该抛弃Express的视图渲染引擎
Nodejs Express框架的一个被人们广为使用的特性是它的渲染引擎.Express视图渲染引擎允许Controller提供一个视图名称和视图模型对象给Express,然后返回由HTTP响应流输出 ...
- centos7 部署openstf
1.安装nodejs,版本需大于6.9(写稿时使用的6.9,7.7.4版本会无法安装zmq): 2.安装android sdk(详细略,百度一大堆),注意必须将platform-tool配置到环境变量 ...
- 学点Groovy来理解build.gradle代码
在写这篇博客时,搜索参考了很多资料,网上对于 Groovy 介绍的博客已经特别多了,所以也就没准备再详细的去介绍 Groovy,本来也就计划写一些自己认为较重要的点.后来发现了 Groovy 的官方文 ...
- win32/mfc/qt 异常处理与总结
际异常一: libcpmtd.lib(xmbtowc.obj) : error LNK2001: unresolved external symbol __CrtDbgReport Debug/B机. ...
- python 、mmap 实现内存数据共享
import mmap mmap_file = None ##从内存中读取信息, def read_mmap_info(): global mmap_file mmap_file.seek(0) ## ...
- 程序猿 tensorflow 入门开发及人工智能实战
tensorflow 中文文档: http://www.tensorfly.cn http://wiki.jikexueyuan.com/project/tensorflow-zh/ tensorfl ...
- cat: can't open '/lib/modules/2.6.35.3-571-gcca29a0/modules.dep': No such file or directory
在使用modprobe 或者modinfo cat: can't open '/lib/modules/2.6.35.3-571-gcca29a0/modules.dep': No such fil ...
- Realm数据持久化方案的简单介绍和使用(二)
接上篇... 4. 可空属性&默认值&忽略属性 默认情况下, 属性值可空, 如果强制要求某个属性非空, 可以使用如下方法: 遵循协议方法 + (NSArray *)requiredPr ...
- 浩哥解析MyBatis源码(四)——DataSource数据源模块
原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6634880.html 1.回顾 上一文中解读了MyBatis中的事务模块,其实事务操作无非 ...
- 老李分享:robotium3.6与4.0 later 的区别 1
老李分享:robotium3.6与4.0 later 的区别 因为下载的直接是最新版本的robotium4.1版,这次碰到gridView问题时,发现网上有getCurrentListViews( ...