[刷题]算法竞赛入门经典(第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 ...
随机推荐
- 百度api的使用
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- rsync+inotify实现文件同步更新(配置)
linux下为了数据安全或者网站同步镜像,不得不考虑一些实时备份的问题,这篇linux下通过rsync+inotify 实现数据实时备份配置过程记录下来,防止遗忘配置过程记录下来,防止遗忘!如有建议技 ...
- Python之路-正则表达式
作业一:整理正则表达式博客 正则表通常被用来检索.替换那些符合某个模式(规则)的文本,为了提取对自己有用的信息,由命令解释执行:而通配符和命令是同一级别,为了提示处理效率,直接由shell解释执行. ...
- Python之路-Linux命令基础(2)
作业一: 1) 新建用户natasha,uid为1000,gid为555,备注信息为"master" 2) 修改natasha用户的家目录为/Natasha 3) ...
- Java面试题:Servlet是线程安全的吗?
Servlet不是线程安全的. 要解释为什么Servlet为什么不是线程安全的,需要了解Servlet容器(即Tomcat)使如何响应HTTP请求的. 当Tomcat接收到Client的HTTP请求时 ...
- [翻译] 使用ElasticSearch,Kibana,ASP.NET Core和Docker可视化数据
原文地址:http://www.dotnetcurry.com/aspnet/1354/elastic-search-kibana-in-docker-dotnet-core-app 想要轻松地通过许 ...
- TableView cell自适应高度-----xib
1.通过xib创建一个cell,将label进行上左下右,进行适配, self.automaticallyAdjustsScrollViewInsets = NO; self.edgesForExte ...
- Java中集合框架,Collection接口、Set接口、List接口、Map接口,已经常用的它们的实现类,简单的JDK源码分析底层实现
(一)集合框架: Java语言的设计者对常用的数据结构和算法做了一些规范(接口)和实现(实现接口的类).所有抽象出来的数据结构和操作(算法)统称为集合框架. 程序员在具体应用的时候,不必考虑数据结构和 ...
- 23(java/io/data_io)
package test_ppt;import java.io.*;public class test_ppt{ public static void main(String args[]) thro ...
- C#各个版本中的新增特性详解
序言 自从2000年初期发布以来,c#编程语言不断的得到改进,使我们能够更加清晰的编写代码,也更加容易维护我们的代码,增强的功能已经从1.0搞到啦7.0甚至7.1,每一次改过都伴随着.NET Fram ...