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来确定. 如果直接用访问下标的形式去做的话. 会强行给他加一个那个关键字( ...
随机推荐
- 虚拟机搭建Zookeeper服务器集群完整笔记
虚拟机搭建Zookeeper服务器集群完整笔记 本笔记主要记录自己搭建Zookeeper服务器的全过程,默认已经安装部署好Centos7. 一.虚拟机下Centos无法联网解决方案 1.首先调整虚拟机 ...
- bootstrap的模态框
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 让ckplayer支持m3u8格式的播放
一 ckplayer官网下载. 直接解压到本地,注意配置里面的默认文件路径,最好是放在服务器的根目录下,这样就可以去访问外链接的资源,官网也是这么推荐的,我这里就直接用node开启一个小服务器. 二 ...
- WMI远程启动软件(某个应用程序)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.M ...
- 微信小程序--试水
应公司需求,接手小程序,在此之前我是一点也没有接触过,对此,拿过小程序文档和官方案例就一顿恶补,在此期间也看过一些小程序建立模型的视频,终于对小程序知晓一二,拿过项目开始研究.好了废话不多说,总结一下 ...
- 转:rabbitMQ 安装与管理
安装环境 虚拟机:VMware® Workstation 10.0.1 build Linux系统:CentOS6.5 官方安装:http://www.rabbitmq.com/install-rpm ...
- delphi 给EXE文件增加区段
学习 PE 可执行文件格式,用 delphi 实现给 EXE 文件增加区段 源码下载(StudyPE.zip) unit uStudyPE; interface uses Classes, SysUt ...
- css 中calc无效属性值问题
width:calc(50%-20px); 这样书写是无效的因为calc中计算的两个因子同运算符号之间必须存在空格:
- windows下python3.5使用pip离线安装whl包
0. 绪论 Windows离线断网环境下安装Python包,配置环境,准备用来生成word模版.姑且记录一下 生产环境 : windows 7 windows10 python 3.5.2 pip 1 ...
- 20160221.CCPP体系详解(0031天)
程序片段(01):01.结构体静态数组.c+02.结构体动态数组.c 内容概要:结构体数组 ///01.结构体静态数组.c #include <stdio.h> #include < ...