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 ...
随机推荐
- Django【第2篇】:Django之反向解析
Django框架之第二篇 一.知识点回顾 1.MTV模型 model:模型,和数据库相关的 template:模板,存放html文件,模板语法(目的是将变量如何巧妙的嵌入到HTML页面中). view ...
- Docker(三):Docker入门教程-CentOS Docker 安装
CentOS Docker 安装 Docker支持以下的CentOS版本: CentOS 7 (64-bit) CentOS 6.5 (64-bit) 或更高的版本 前提条件 目前,CentOS 仅发 ...
- 【NOIP2013模拟】归途与征程
题目 分析 好吧...明显是暴力题. 首先,把A串分成只有小写字母组成的小分串,按顺序存放:A[1].A[2].A[3]--. 对于同构循环串,显然把两个B串合在一起,成为一个新的C串.\(C[i.. ...
- php 单示例编程
<?php defined('SYSPATH') or die('No direct script access.'); class Kohana_BOTA { //私有构造方法,防止再次实例化 ...
- 【CF1251E】Voting(贪心)
题意:有n个人,需要搞到全部n个人的票,搞到第i个人的票有两种方式:之前已经搞到mi个人的票,或者直接花费pi 问最小的搞到所有票的总代价 n<=2e5,1<=p[i]<=1e9,0 ...
- 蒙特卡洛(Monte Carlo)方法求面积
如图,刷微博时,看到一个问题,第一个想到的就是用蒙特卡洛方法求解,当时正在练python,于是尝试用python编写程序. import random # 先求s1 k=0 n=100000000 f ...
- 学习C#20天有感
自学C#有20多天了,期间出差去深圳一周,每天平均学习4小时左右,看书+视频,之前有点C语言基础(仅限于基础哈哈),计划30内把C#的基本语法和SQL的基本语法熟悉,把面向对象相对深入的理解一些,然后 ...
- PHP 设计模式总结
回想了一下php的设计模式,好像记得不完全了.此处对php设计模式重新做一下复习总结. 单例模式 单例模式的核心只包括一个特殊的类,保证系统中只能有一个实例,即一个类中只能有一个实例化对象,避免系统中 ...
- MySQL主从复制中replicate-ignore-db replicate-wild-ignore-table的应用
MySQL主从复制中replicate-ignore-db replicate-wild-ignore-table的应用 replicate-ignore-dbreplicate-wild-ignor ...
- DAY 6 上午
如果不是割点,答案减少2(n-1) 如果删去割点,删去之后整个图分成多个连通块 每一个联通块的大小*其他连通块的大小之和 先求出缩点之后的树 加尽可能少的边使树变成一个边双 找出树上的所有叶子节点(度 ...