CSU 1113 Updating a Dictionary
Time Limit: 1000MS | Memory Limit: 131072KB | 64bit IO Format: %lld & %llu |
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
------------------------------------------------------------------------------
简单题,注意implementation。
#include <cstdio>
#include <iostream>
#include <cctype>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#define pb push_back using namespace std;
map<string, string> a, b;
vector<string> aa, bb;
int main(){
//freopen("in", "r", stdin);
int T;
string s, t;
char ch;
for(cin>>T; T--; cout<<endl){
for(;cin>>ch;){
if(isalpha(ch)) s+=ch;
else if(ch==':'){
while(cin>>ch, isdigit(ch)){
t+=ch;
}
a[s]=t;
aa.pb(s);
s.clear();
t.clear();
if(ch=='}') break; //error
}
}
for(;cin>>ch;){
if(isalpha(ch)) s+=ch;
else if(ch==':'){
while(cin>>ch, isdigit(ch)){
t+=ch;
}
bb.pb(s);
b[s]=t;
s.clear();
t.clear();
if(ch=='}') break; //error
}
}
sort(aa.begin(), aa.end());
sort(bb.begin(), bb.end());
bool fir=true, nc=true;
for(int i=; i<bb.size(); i++){
string &tmp=bb[i];
if(a[tmp].empty()){
if(fir) cout<<'+'+tmp, fir=false;
else cout<<','+tmp;
}
}
if(!fir) cout<<endl, nc=;
fir=true;
for(int i=; i<aa.size(); i++){
string &tmp=aa[i];
if(b[tmp].empty()){
if(fir) cout<<'-'+tmp, fir=false;
else cout<<','+tmp;
}
}
if(!fir) cout<<endl, nc=;
fir=true;
for(int i=; i<bb.size(); i++){
string &tmp=bb[i];
if(!a[tmp].empty()&&!b[tmp].empty()&&a[tmp]!=b[tmp]){
if(fir) cout<<'*'+tmp, fir=false;
else cout<<','+tmp;
}
}
if(!fir) cout<<endl, nc=;
if(nc) cout<<"No changes"<<endl;
a.clear(), b.clear(), aa.clear(), bb.clear();
} }
#include <cstdio>
#include <iostream>
#include <cctype>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#define pb push_back using namespace std;
map<string, string> a, b;
vector<string> aa, bb;
int main(){
freopen("in", "r", stdin);
int T;
string s, t;
char ch;
for(cin>>T; T--; cout<<endl){
for(;cin>>ch;){
if(isalpha(ch)) s+=ch;
else if(ch==':'){
while(cin>>ch, isdigit(ch)){
t+=ch;
}
a[s]=t;
aa.pb(s);
s.clear();
t.clear();
}
if(ch=='}') break;
}
//cout<<aa.size()<<endl;
for(;cin>>ch;){
if(isalpha(ch)) s+=ch;
else if(ch==':'){
while(cin>>ch, isdigit(ch)){
t+=ch;
}
bb.pb(s);
b[s]=t;
s.clear();
t.clear();
}
if(ch=='}') break;
}
sort(aa.begin(), aa.end());
sort(bb.begin(), bb.end());
bool fir=true, nc=true;
for(int i=; i<bb.size(); i++){
string &tmp=bb[i];
if(a[tmp].empty()){
if(fir) cout<<'+'+tmp, fir=false;
else cout<<','+tmp;
}
}
if(!fir) cout<<endl, nc=;
fir=true;
for(int i=; i<aa.size(); i++){
string &tmp=aa[i];
if(b[tmp].empty()){
if(fir) cout<<'-'+tmp, fir=false;
else cout<<','+tmp;
}
}
if(!fir) cout<<endl, nc=;
fir=true;
for(int i=; i<bb.size(); i++){
string &tmp=bb[i];
if(!a[tmp].empty()&&!b[tmp].empty()&&a[tmp]!=b[tmp]){
if(fir) cout<<'*'+tmp, fir=false;
else cout<<','+tmp;
}
}
if(!fir) cout<<endl, nc=;
if(nc) cout<<"No changes"<<endl;
a.clear(), b.clear(), aa.clear(), bb.clear();
}
}
CSU 1113 Updating a Dictionary的更多相关文章
- CSU 1113 Updating a Dictionary(map容器应用)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 解题报告:输入两个字符串,第一个是原来的字典,第二个是新字典,字典中的元素的格式为 ...
- 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 ...
- [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& ...
随机推荐
- for循环的三种写法
第一种写法 传统的方法,遍历数组 String[] arr = { "amy", "heinrich", "cindy", "g ...
- 08Spring_Spring和junit测试集成
第一步: 在项目导入 spring-test-3.2.0.RELEASE.jar 第二步: 编写测试类
- git config配置文件
设置 git status的颜色. git config --global color.status auto 一.Git已经在你的系统中了,你会做一些事情来客户化你的Git环境.你只需要做这些设置一 ...
- 如何将NTFS格式的移动硬盘挂接到Mac OS上进行读写(Read/Write)操作
现在硬盘便宜,很多同学都有移动硬盘,如果你同时使用Windows与Mac OS的话,移动硬盘最好不要使用NTFS文件系统,否则在Mac OS上,你只能读你的移动硬盘,不能写. 但是实际上的情况是,移动 ...
- 挖Linux中的古老缩略语
[2005-06-22 15:23][Nigel McFarlane][TechTarget] <<阅读原文>> Unix已经有35年历史了.许多人认为它开始于中世纪,这个中世 ...
- php基础19:文件
<?php //1.打开文件的更好的方法是通过 fopen() 函数.此函数为您提供比 readfile() 函数更多的选项. //fopen() 的第一个参数包含被打开的文件名,第二个参数规定 ...
- PHP基础14:表单处理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Microsoft Visual Studio 正忙
简介:Microsoft Visual Studio 正忙,Microsoft Visual Studio 正在等待内部操作完成.如果经常在正常使用的情况下遇到此延迟, 请向Microsoft报告此情 ...
- 使用Spring.net中对Ado.net的抽象封装来访问数据库
使用Spring.net中对Ado.net的抽象封装来访问数据库 Spring.NET是一个应用程序框架,其目的是协助开发人员创建企业级的.NET应用程序.它提供了很多方面的功能,比如依赖注入 ...
- Linux(9.21-9.27)学习笔记
一.Vim的基本操作. Normal模式下 1.h 键 向左移动光标 2. j 键 向下移动光标 3. k 键 向上移动光标 4. l键 向右移动光标 5.x 键 删除光标所在位置的 ...