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& ...
随机推荐
- 【转】一篇很全面的freemarker教程---有空慢慢实践
FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主要由如下4个部分组成: 1,文本:直接输出的部分 2,注释:<#-- ... -->格式部分,不会输 ...
- 汇编查看StackFrame栈帧
INCLUDE Irvine32.inc myProc PROTO, x:DWORD, y:DWORD .data .code main proc mov eax,0EAEAEAEAh mov ebx ...
- 如何写出无法维护的代码(JAVA版)
程序命名(针对那些不能混淆的代码) 容易输入的名字.比如:Fred,asdf 单字母的变量名.比如:a,b,c, x,y,z,或者干脆上中文比如(阿隆索肯德基) 有创意地拼写错误.比如:SetPint ...
- [LeetCode]题解(python):054-Spiral Matrix
题目来源 https://leetcode.com/problems/spiral-matrix/ Given a matrix of m x n elements (m rows, n column ...
- Wall---hdu1348(求凸包周长 模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 求凸包周长+2*PI*L: #include <stdio.h> #include ...
- 获取网络状态ios(2G、3G、4G、Wifi)
+(NSString *)getNetWorkStates{UIApplication *app = [UIApplication sharedApplication];NSArray *childr ...
- ant 执行到javac时运行中止,怎么办?
今天下午我用ant,明明都能打出target.后来改了点代码就不行了,执行到compile的javac时运行中止,真是见鬼了. 在ant构建文件上右击,点击"run as"-> ...
- ul和ol的一些知识
ul和ol的一些知识 div#div0 ul{ border:1px solid #ccc; list-style:none; } div#div0 ul li{ border:1px solid g ...
- Sequential Read Ahead For SQL Server
Balancing CPU and I/O throughput is essential to achieve good overall performance and to maximize ha ...
- Linux 中的零拷贝技术,第 1 部分
概述 本系列由两篇文章组成,介绍了当前用于 Linux 操作系统上的几种零拷贝技术,简单描述了各种零拷贝技术的实现,以及它们的特点和适用场景.本文是本系列文章的第一部分,主要是介绍一些零拷贝技术的相关 ...