Uva - 12504 - Updating a Dictionary
全是字符串相关处理,截取长度等相关操作的练习
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
map<string, string> ma;
string dictOld, dictNew;
string ad[102], del[102], cha[102];
// 分别存储增加的,减少的,变化的关键字
cin >> dictOld >> dictNew;
int addCount = 0;
int deleteCount = 0;
int changeCount = 0;
int a = 0;
while (dictOld.find(',', a + 1) < dictOld.size()) {
// 这里截取方法比较重要
string s(dictOld, a + 1, dictOld.find(',', a + 1) - a - 1);
string kay(s, 0, s.find(':', 0));
string value(s, s.find(':', 0) + 1, s.size() - s.find(':', 0));
ma.insert(pair<string, string>(kay, value));
a = dictOld.find(',', a + 1);
}
string s(dictOld, a + 1, dictOld.find('}', a + 1) - a - 1);
string kay(s, 0, s.find(':', 0));
string value(s, s.find(':', 0) + 1, s.size() - s.find(':', 0));
if (kay.size()) {
ma.insert(pair<string, string>(kay, value));
}
a = 0;
while (dictNew.find(',', a + 1) < dictNew.size()) {
string s(dictNew, a + 1, dictNew.find(',', a + 1) - a - 1);
string key(s, 0, s.find(':', 0));
string value(s, s.find(':', 0) + 1, s.size() - s.find(':', 0));
if (ma.find(key) == ma.end()) {
ad[addCount++] = key;
}
else {
string temp = ma.find(key)->second;
if (temp != value) {
cha[changeCount++] = key;
}
ma.erase(key);
}
a = dictNew.find(',', a + 1);
}
string s1(dictNew, a + 1, dictNew.find('}', a + 1) - a - 1);
string key1(s1, 0, s1.find(':', 0));
string value1(s1, s1.find(':', 0) + 1, s1.size() - s1.find(':', 0));
if (key1.size()) {
if (ma.find(key1) == ma.end()) {
ad[addCount++] = key1;
}
else {
string temp = ma.find(key1)->second;
if (temp != value1) {
cha[changeCount++] = key1;
}
ma.erase(key1);
}
}
while (ma.begin() != ma.end()) {
string temp = ma.begin()->first;
del[deleteCount++] = temp;
ma.erase(temp);
}
if (addCount == 0 &&
deleteCount == 0 &&
changeCount == 0) {
cout << "No changes\n";
}
else {
if (addCount) {
sort(ad, ad + addCount);
cout << "+";
for (int i = 0; i < addCount; i++) {
if (i) {
cout << ",";
}
cout << ad[i];
}
cout << endl;
}
if (deleteCount) {
sort(del, del + deleteCount);
cout << "-";
for (int i = 0; i < deleteCount; i++) {
if (i) {
cout << ",";
}
cout << del[i];
}
cout << endl;
}
if (changeCount) {
sort(cha, cha + changeCount);
cout << "*";
for (int i = 0; i < changeCount; i++) {
if (i) {
cout << ",";
}
cout << cha[i];
}
cout << endl;
}
}
cout << endl;
}
return 0;
}
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(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 ...
- 【习题 5-11 UVA 12504 】Updating a Dictionary
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 不确定某个map里面是否有某个关键字的时候. 要用find来确定. 如果直接用访问下标的形式去做的话. 会强行给他加一个那个关键字( ...
随机推荐
- three.js 3D 动画场景
Three.js 是一款运行在浏览器中的 3D 引擎,你可以用它创建各种三维场景,包括了摄影机.光影.材质等各种对象.使用它它能让 WebGL 变得更加简单. 下面用Three.js渲染一个物体360 ...
- requestAnimationFrame之缓动的应用
之前需要使用的定时器的时,立马想到的是setInterval(),用着用着就成为习惯,并没有遇到什么不妥之处.习惯性的操作往往容易让一个人拒绝尝试一些其他的方法.现在的方法用得好好的,没事干啥找其他法 ...
- RHEL(红帽七)的DNS配置
RHEL7的DNS配置 本文中用到的所有参数均位于文末附录中 查询bind-chroot这个安装包 Yum 安装 bind-chroot 进入named.conf文件 复制以下参数进去 进入这个文 ...
- 蚂蚁代理免费代理ip爬取(端口图片显示+token检查)
分析 蚂蚁代理的列表页大致是这样的: 端口字段使用了图片显示,并且在图片上还有各种干扰线,保存一个图片到本地用画图打开观察一下: 仔细观察蓝色的线其实是在黑色的数字下面的,其它的干扰线也是,所以这幅图 ...
- Java第5次实验提纲(集合)
PTA与参考资料 重要参考-集合简述 题集:jmu-Java-05-集合 集合实验文件 第1次实验 1.1 7-1ArrayListIntegerStack(课堂演示) 注1:不要导入java.awt ...
- Ubuntu批量修改文件名后缀
比如把当前文件夹下所有scss文件后缀改为less rename 's/\.scss/\.less/' ./*
- jboss规则引擎KIE Drools 6.3.0 Final 教程(2)
使用JAVA程序调用规则-运行KIE-DROOLS上的规则 第一步:建立一个MAVEN的Java工程 POM.XML 给出pom.xml文件 <project xmlns="http: ...
- CentOS 7 下使用虚拟环境Virtualenv安装Tensorflow cpu版记录
1.首先安装pip-install 在使用centos7的软件包管理程序yum安装python-pip的时候会报一下错误: No package python-pip available. Error ...
- Android图表库MPAndroidChart(十)——散点图的孪生兄弟气泡图
Android图表库MPAndroidChart(十)--散点图的孪生兄弟气泡图 起泡图和散点图如出一辙,但是个人认为要比散点图好看一点,我们来看下实际的演示效果 这个和散点图的实现很相似,我们一起来 ...
- SQL语言四大类
SQL语言四大类 SQL语言共分为四大类:数据查询语言DQL,数据操纵语言DML,数据定义语言DDL,数据控制语言DCL. 数据查询语言DQL 数据查询语言DQL基本结构是由SELECT子句, ...