H-Updating a Dictionary (模拟)
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
直接模拟即可,这里用到了map,queue,string,stringstream,总之全用的标准库(咳咳咳),打算在重新写一份代码(代码待补),不借助map和queue,还有一件事,这道题提交了好多次都是WA。。。然后就把题读了好几遍,没发现什么特殊的情况存在,然后注释掉了一句代码就过了,std::ios::sync_with_stdio(false),就这句,解除cin与stdin的同步,据说会加快cin的速度,我怕会超时就把这段代码加上了(最后80ms),结果问题就出在这了,还有就是换行cout不用<<endl貌似也能加快速度。。。
代码:
#include<iostream>
#include<sstream>
#include<string>
#include<queue>
#include<map>
using namespace std; map<string,string> mp1,mp2;
typedef queue<string> Queue;
Queue New,Change,None; void Replace(string &str){
int len = str.size();
for(int i=;i<len;i++)
if(str[i] == ':'|| str[i]=='{' || str[i]=='}' || str[i] == ',') str[i] = ' ';
} void String_work(string &pre,string now){
Replace(pre); Replace(now);
stringstream ss(pre),mm(now);
string tmp,str;
while(ss >> str){
ss >> tmp;
mp1[str] = tmp;
}
while(mm >> str){
mm >> tmp;
mp2[str] = tmp;
}
} void Add_to_queue(){
map<string,string> ::iterator it;
for(it=mp2.begin();it!=mp2.end();it++){
if(mp1.find((*it).first)==mp1.end())
New.push((*it).first);
else if(mp1[(*it).first]!=(*it).second) {
Change.push((*it).first);
mp1.erase((*it).first);
}
else mp1.erase((*it).first); }
for(it=mp1.begin();it!=mp1.end();it++){
None.push((*it).first);
}
} void print_ans(Queue &Q,char c){
cout<< c;
while(!Q.empty()){
cout << Q.front(); Q.pop();
if(Q.empty()) cout << "\n" ; else cout <<",";
}
} void Solve_question(){
bool flag = true;
if(!New.empty()) {flag = false; print_ans(New,'+');}
if(!None.empty()) {flag = false; print_ans(None,'-');}
if(!Change.empty()) {flag = false; print_ans(Change,'*');}
if(flag) cout <<"No changes\n";
cout <<"\n";
} void Init_map(){
mp1.clear(); mp2.clear();
} int main(){
//std::ios::sync_with_stdio(false);!!!不能用!!!切记!!!
int T;
string pre,now;
cin >> T;
while(T--){
Init_map();
cin >> pre >> now;
String_work(pre,now);
Add_to_queue();
Solve_question();
}
}
H-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 ...
- Problem C Updating a Dictionary
Problem C Updating a Dictionary In this problem, a dictionary is collection of key-value pairs, ...
- 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 ...
- Updating a Dictionary UVA - 12504
In this problem, a dictionary is collection of key-value pairs, where keys are lower-case letters, a ...
- CSU 1113 Updating a Dictionary
传送门 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Description In th ...
- H.数7(模拟)
1212: H.数7 时间限制: 1 Sec 内存限制: 64 MB 提交: 8 解决: 5 标签提交统计讨论版 题目描述 数7是一个简单的饭桌游戏,有很多人围成一桌,先从任意一人开始数数,1.2 ...
- 【UVA】12504 Updating a Dictionary(STL)
题目 题目 分析 第一次用stringstream,真TMD的好用 代码 #include <bits/stdc++.h> using namespace std; int ...
随机推荐
- ES6 Module(模块)
1.export命令 一个模块就是一个独立的文件. 该文件内部的所有变量,外部无法获取. 如果你希望外部能够读取模块内部的某个变量,就必须使用export关键字输出该变量. 下面是一个 JS 文件,里 ...
- SSH自动登录脚本
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11926792.html vi app-stg.sh #!/usr/bin/expect -f #aut ...
- IDEA创建SpringBoot,并实现、运行简单实例
1.打开IDEA,点击 +Create New Project. 开始创建一个新项目. 2.在左侧菜单找到并点击 Spring Initializr,点击next.注意,这里idea默认使用https ...
- ZeroMQ的进阶
上一篇博文我们对ZeroMQ的经典模式做了写Demo让他跑起来了,但实际开发中我们可能面临一些远比上述复杂的场景.这时候我们需要进一步的对经典模式进行扩展,所幸ZeroMQ已经为我们做好了准备工作. ...
- Codeforces Round #579 (Div. 3) 套题 题解
A. Circle of Students 题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
- 【bzoj2946】[Poi2000]公共串
*题目描述: 给出几个由小写字母构成的单词,求它们最长的公共子串的长度. 任务: l 读入单词 l 计算最长公共子串的长度 l 输出结果 *输入: 文件的第一行是整数 n,1<=n<=5, ...
- Coffee Chicken
Coffee Chicken 字符串斐波那契 输出第s[n]个字符串的第k位及后十位 暴力算出前20项,超过20,跑dfs #include<bits/stdc++.h> using na ...
- [codeforces743C]:Vladik and fractions(数学)
题目传送门 题目描述 请找出一组合法解使得$\frac{1}{x}+\frac{1}{y}+\frac{1}{z}=\frac{2}{n}$成立. 其中$x,y,z$为正整数且互不相同. 输入格式 一 ...
- [git] 如何处理push失败的commit
在使用git及github时,遇到一个问题:commit了一个超过100M的大文件,然后在push时失败,然后就再也无法push了,本地大文件删除了,再commit,再push也还是提示有大文件提交. ...
- React-Native 之 GD (八)GET 网络请求封装
1.到这里,相信各位对 React-Native 有所熟悉了吧,从现在开始我们要慢慢往实际的方向走,这边就先从网络请求这部分开始,在正式开发中,网络请求一般都单独作为一部分,我们在需要使用的地方只需要 ...