宁波工程学院 [1369] A Breaking Computer deque的应用
来源:互联网 发布:小米网络电视直播 编辑:程序博客网 时间:2024/04/29 16:41
hnust_xiehonghao
[1369] A Breaking Computer
Oh my god.My computer is break.When I writing something,the home and the end always is working.But I also write too quakily,
even I don't see the screen.OK,when I finish a work ,can you tell me the work become in end?
We modified the sample output, please check it.
even I don't see the screen.OK,when I finish a work ,can you tell me the work become in end?
We modified the sample output, please check it.
This have some cases.
Every case have a sentence(length< 200000 Include (A->Z a->z 0->9)).Then '[' is the home,']' is the end;
Every case have a sentence(length< 200000 Include (A->Z a->z 0->9)).Then '[' is the home,']' is the end;
Input a sentence.
Printf the finally sentence.
Printf the finally sentence.
123[4123[45]6123[45]6[7]8
412345123674512368
无
Three God
http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1369
题意:输入一串字符 由于电脑坏了 有可能输入的过程中 鼠标自己乱跑 可能跑到字符串的开头 和结尾 [ 表示输入的过程中跑到了开头 ] 表示跑到了末尾
比如123[45]6[7]8 先输入123 此时 [ 跑到了开头 输入45 变成了 45123 遇到 ] 跑到最后 输入6 变成451236
之后遇到 [ 跑到开头 输入7变成了 7451236 之后遇到 ] 跑到最后 输入8 变成了 答案74512368
思路 双向队列
#include<stdio.h>#include<deque>#include<vector>using namespace std;char s[200005];int main(){deque<char>dq(20);deque<char>::iterator it;vector<char>a;vector<char>::iterator ii;int i,flag=0,last; while(scanf("%s",s)!=EOF) { while(!dq.empty()) dq.pop_front(); a.clear(); flag=0;last=0; for(i=0;s[i]!='\0';i++) { if(s[i]!='['&&s[i]!=']') { if(flag) { a.push_back(s[i]); } else dq.push_back(s[i]); continue; } if(s[i]=='[') { flag=1; if(a.empty()) continue;ii=a.end();ii--;for(;ii>=a.begin();ii--)dq.push_front(*ii);a.clear(); } else if(s[i]==']') { flag=0; if(a.empty()) continue;ii=a.end();ii--;for(;ii>=a.begin();ii--)dq.push_front(*ii);a.clear(); } } if(!a.empty()) {ii=a.end();ii--;for(;ii>=a.begin();ii--)dq.push_front(*ii);a.clear(); } it=dq.begin(); for(it;it!=dq.end();it++) printf("%c",*it); printf("\n"); } return 0;}
反思: 本题 我一开始用1个小时的时间 才拍出一个通过样例 的程序 居然发现自己理解错题意了 每次都是这样 自己的这个缺点很严重 以后千万要注意
另外 如果一个程序修改了很长时间 还很复杂 而且代码不长 一定要重新拍一个 这样思路更加清晰
- 宁波工程学院 [1369] A Breaking Computer deque的应用
- NOJ [1369] A Breaking Computer
- 宁波工程学院 OJ [1282] A Bouquet of Flowers 最大的k个数的和
- 宁波工程学院 1346 二分
- 懒惰的风纪委Elaine(宁波工程学院)
- 宁波工程学院[1409] 鼹鼠鼹鼠你不出来 大数处理 模拟 很好的题
- 宁波工程学院 OJ [1347] 老虎满坡找灰兔
- 嘛~付钱吧!(宁波工程学院)
- 宁波工程学院 OJ [1292] Jokes 一堆数中对每个数与前k个重复的数字的个数
- 宁波工程学院[1349] 刺儿扎痛虎屁股 根据公式放刺,求1-n哪个洞放的刺最多
- 宁波工程学院 [1271] Nth Day is Which Day 输出第n天的日期 (要求算法很快速,解决超时)
- 宁波工程学院 [1346] 虎追兔,兔躲虎 二分法 精确度小细节
- NUBT 1651 Red packet(红包问题,二分,宁波工程学院在线评测)
- 男人的定义:A man provides. (Breaking Bad 中一段关于男人的对话)
- 双端队列(deque)的应用
- 宁波工程学院 1350 气坏了老虎乐坏了兔 记忆化搜索 帅呆了
- 宁波工程学院[1372] Do What n个数中取出某些数使得和大于T且和最小
- 创意视觉应用︱基于深度学习的CVaaS计算机视觉即服务案例(Computer Vision as a Service)
- IE条件注释
- 关于线程的几个问题
- SQLServer的数据类型
- 【多边形面积】求多边形的面积 pol
- 学科前沿技术(amdahl定律对多核的影响)
- 宁波工程学院 [1369] A Breaking Computer deque的应用
- SQL SERVER 关于用户的sql语句
- APUE学习笔记——第十六章 网络IPC:套接字
- 旧日志整理之二: 重读华罗庚的故事
- C# DllImport的用法
- HDU-1007 Quoit Design
- js 命名规范
- CSS禁止选择文本功能(兼容IE,火狐等浏览器)
- 使用旧的控制文件恢复数据库