csuoj 1113: Updating a Dictionary
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113
1113: Updating a Dictionary
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 491 Solved: 121
[Submit][Status][Web Board]
Description
Input
Output
Sample Input
3
{a:3,b:4,c:10,f:6}
{a:3,c:5,d:10,ee:4}
{x:1,xyz:123456789123456789123456789}
{xyz:123456789123456789123456789,x:1}
{first:1,second:2,third:3}
{third:3,second:2}
Sample Output
+d,ee
-b,f
*c No changes -first
HINT
Source
分析:
STL容器的使用。
AC代码:
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include <cctype>
#include<map>
using namespace std;
char s1[];
char s2[];
char s3[];
char s4[];
bool cmp(string ss,string sss)
{
return ss<sss;
}
string st,ed;
int main()
{
int T,t1,t2;
scanf("%d",&T);
gets(s1);
while(T--)
{ map<string,string>ss1;
map<string,string>ss2;
map<string,string>::iterator it;
string ss[];
string plu[],dir[],key[];
int k1 = ,k2 =,k3 =,k4=;
ss1.clear();
ss2.clear();
for(int i=;i<;i++)
{
ss[i].clear();
plu[i].clear();
dir[i].clear();
key[i].clear();
}
gets(s1);
gets(s2);
st = ed = "";
int len1 = strlen(s1);
int len2 = strlen(s2);
for(int i=;i<len1;i++)
{
if(isdigit(s1[i]))
ed = ed+s1[i];
else if(isalpha(s1[i]))
st = st+s1[i];
else if(s1[i] == ',')
{
ss1[st] =ed;
ss[k4++] = st;
st = ed = "";
}
else if(s1[i] == '}')
{
if(st!="")
{
ss[k4++] = st;
ss1[st] =ed;
}
st = ed = "";
}
}
for(int i=;i<len2;i++)
{
if(isdigit(s2[i]))
ed =ed+s2[i];
else if(isalpha(s2[i]))
st = st+s2[i];
else if(s2[i] == ',')
{
it = ss1.find(st);
if(it!=ss1.end())//如果找到
{
if(ss1[st] != ed)//增加的
key[k3++] = st;
}
else
{
plu[k1++] = st;
}
ss2[st] =ed;
st = ed = "";
}
else if(s2[i] == '}')
{
if(st!="")
{
it = ss1.find(st);
if(it!=ss1.end())//如果找到
{
if(ss1[st] != ed)//增加的
key[k3++] = st;
}
else
{
plu[k1++] = st;
}
ss2[st] =ed;
}
st = ed = "";
}
}
for(int i=;i<k4;i++)
{
it = ss2.find(ss[i]);
if(it == ss2.end())//如果没有找到
{
dir[k2++] = ss[i];
}
}
if(k1+k2+k3 == )
printf("No changes\n");
else
{
sort(plu,plu+k1,cmp);
for(int i=;i<k1;i++)
{
if(i==) printf("+%s",plu[i].c_str());
else printf(",%s",plu[i].c_str());
}
if(k1>) printf("\n"); sort(dir,dir+k2,cmp);
for(int i=;i<k2;i++)
{
if(i==) printf("-%s",dir[i].c_str());
else printf(",%s",dir[i].c_str());
}
if(k2>) printf("\n"); sort(key,key+k3,cmp);
for(int i=;i<k3;i++)
{
if(i==) printf("*%s",key[i].c_str());
else printf(",%s",key[i].c_str());
}
if(k3>) printf("\n"); }
printf("\n");
}
return ;
}
csuoj 1113: Updating a Dictionary的更多相关文章
- CSU 1113 Updating a Dictionary(map容器应用)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 解题报告:输入两个字符串,第一个是原来的字典,第二个是新字典,字典中的元素的格式为 ...
- CSU 1113 Updating a Dictionary
传送门 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Description In th ...
- 湖南生第八届大学生程序设计大赛原题 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 ...
- [ACM_模拟] UVA 12504 Updating a Dictionary [字符串处理 字典增加、减少、改变问题]
Updating a Dictionary In this problem, a dictionary is collection of key-value pairs, where keys ...
- 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 ...
- Uva 511 Updating a Dictionary
大致题意:用{ key:value, key:value, key:value }的形式表示一个字典key表示建,在一个字典内没有重复,value则可能重复 题目输入两个字典,如{a:3,b:4,c: ...
- Uva - 12504 - Updating a Dictionary
全是字符串相关处理,截取长度等相关操作的练习 AC代码: #include <iostream> #include <cstdio> #include <cstdlib& ...
随机推荐
- Android之Fragment学习笔记②(Fragment生命周期)
一. Fragment生命周期图 二.Fragment生命周期方法介绍 Fragment的生命周期和activity生命周期很像,其生 ...
- myeclipse 8.5 常用快捷键【转】
eclipse 里查找行号的方法 今天开发的时候为了方便查找报错行的位置,特意在网上找了一下快捷键是什么,现做记录. 在Eclipse里的show the line number 后,使用" ...
- hdc cdc
CWindowDC dc(this); HDC hdc=dc.GetSafeHdc(); using namespace Gdiplus; Graphics graphics(hdc); graphi ...
- android jdbc 远程数据库
http://blog.csdn.net/conowen/article/details/7435231/
- yii2 实现多表联查
- Magento打印(配送单、退款单、发票)时PDF中的乱码问题
我使用Magento1.4.2,在其自带的TTF文件不能很好地解析中文字符,TTF文件的位置在网站根目录下的/lib/LinLibertineFont/中.打印的中文字符都是这样的 解决方法: 1.在 ...
- [LeetCode]题解(python):102 Binary Tree Level Order Traversal
题目来源 https://leetcode.com/problems/binary-tree-level-order-traversal/ Given a binary tree, return th ...
- Java学习-022-Properties 文件数据写入
Properties 配置文件写入主要通过 Properties.setProperty 和 Properties.store 两个方法,此文以一个简单的 properties 文件写入源码做示例. ...
- 概率dp入门
概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. poj2096:Collecting Bugs #include <i ...
- 微信公众平台开发(110) 微信连Wi-Fi
关键字:微信公众平台 微信连Wi-Fi 微信 WiFi 硬件鉴权作者:方倍工作室 原文:http://www.cnblogs.com/txw1958/p/weixin-wifi.html 微信连Wi- ...