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& ...
随机推荐
- zepto.js 源码解析
http://www.runoob.com/w3cnote/zepto-js-source-analysis.html Zepto是一个轻量级的针对现代高级浏览器的JavaScript库, 它与jqu ...
- scanf和cin的差异
scanf和cin的差异 引例:http://www.cnblogs.com/shenben/p/5516996.html 大家都知道,在C++中有两种输入.输出方式—scanf和cin,但是,它们之 ...
- WPF用ShowDialog()弹出窗体时控制该窗体的显示位置,并传值回父窗体
原文:http://blog.csdn.net/kiss0622/article/details/5852153 方法一: 1.父窗口代码 Window1.xaml.cs private void B ...
- Math类和Random类(数学公式相关类)
Math 类包含用于执行基本数学运算的方法,如初等指数.对数.平方根和三角函数. 常用方法: 1.static 数值类型 abs(数值类型 a) 返回 double 值的绝对值. 2.sta ...
- [原]iBatis.Net(C#)系列一:简介及运行环境
转载请注明http://www.cnblogs.com/13590/archive/2013/02/27/2934580.html 摘要:介绍iBatis.Net的基本情况和运行原理,运行环境中各参数 ...
- JS 之匿名函数
匿名函数以及闭包 匿名函数就是没有名字的函数.闭包是指有权访问另一个函数作用域中的变量的函数.创建闭包的常见方式是在一个函数的内部创建另一个函数.闭包会携带包含它的函数的作用域,因此会比其他函数占用更 ...
- [CareerCup] 7.6 The Line Passes the Most Number of Points 经过最多点的直线
7.6 Given a two-dimensional graph with points on it, find a line which passes the most number of poi ...
- [CareerCup] 9.1 Climbing Staircase 爬楼梯
9.1 A child is running up a staircase with n steps, and can hop either 1 step, 2 steps, or 3 steps a ...
- Linux下OpenSSL的安装与使用
Linux下OpenSSL的安装与使用 OpenSSL简介 OpenSSL是一个SSL协议的开源实现,采用C语言作为开发语言,具备了跨平台的能力,支持Unix/Linux.Windows.Mac OS ...
- AutoLayout 约束与frame、bounds的设置
介绍 关于AutoLayout的介绍可参考: 使用解读: https://segmentfault.com/a/1190000004386278 iOS 屏幕适配,autoResizing autoL ...