uva - Broken Keyboard (a.k.a. Beiju Text)(链表)
11988 - Broken Keyboard (a.k.a. Beiju Text)
You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problem
with the keyboard is that sometimes the “home” key or the “end” key gets automatically pressed
(internally).
You’re not aware of this issue, since you’re focusing on the text and did not even turn on the
monitor! After you finished typing, you can see a text on the screen (if you turn on the monitor).
In Chinese, we can call it Beiju. Your task is to find the Beiju text.
Input
There are several test cases. Each test case is a single line containing at least one and at most 100,000
letters, underscores and two special characters ‘[’ and ‘]’. ‘[’ means the “Home” key is pressed
internally, and ‘]’ means the “End” key is pressed internally. The input is terminated by end-of-file
(EOF).
Output
For each case, print the Beiju text on the screen.
Sample Input
This_is_a_[Beiju]_text
[[]][][]Happy_Birthday_to_Tsinghua_University
Sample Output
BeijuThis_is_a__text
Happy_Birthday_to_Tsinghua_University
题解:
给定一个字符串,内部含有”【“和”】“光标转移指令,
【代表光标移向文章头,】代表光标移向文章尾,问最终在屏幕上显示的字符串序列是?
Cur代表当前光标的位置,en代表当前结束的位置。。。模拟输入就好了,用链表;
链表,好题,代码好吊,看了半天,越看越感觉吊;
代码:
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=1e5+100;
int en,cur,next[MAXN];
char s[MAXN];
int main(){
while(~scanf("%s",s+1)){
int len=strlen(s+1);
cur=en=0;
next[0]=0;
for(int i=1;i<=len;i++){
if(s[i]=='[')cur=0;
else if(s[i]==']')cur=en;
else{
next[i]=next[cur];
next[cur]=i;
if(cur==en)en=i;
cur=i;
}
}
for(int i=next[0];i!=0;i=next[i])printf("%c",s[i]);
puts("");
}
return 0;
}
uva - Broken Keyboard (a.k.a. Beiju Text)(链表)的更多相关文章
- UVa 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...
- 破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)
破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988) 题意描述 你在输入文章的时候,键盘上的Home键和End键出了问题,会不定时的按下. ...
- UVA——11988 Broken Keyboard (a.k.a. Beiju Text)
11988 Broken Keyboard (a.k.a. Beiju Text)You’re typing a long text with a broken keyboard. Well it’s ...
- B - Broken Keyboard (a.k.a. Beiju Text)
Problem B Broken Keyboard (a.k.a. Beiju Text) You're typing a long text with a broken keyboard. Well ...
- N - Broken Keyboard (a.k.a. Beiju Text)(DFS,链表)
N - Broken Keyboard (a.k.a. Beiju Text) Time Limit:1000MS Memory Limit:0KB 64bit IO Format:% ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...
- Broken Keyboard (a.k.a. Beiju Text) UVA - 11988
You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...
- Broken Keyboard (a.k.a. Beiju Text) 思路
问题:You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problem ...
- B - Broken Keyboard (a.k.a. Beiju Text) 数组模拟链表
You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...
随机推荐
- DLL与EXE之间的通讯调用 以及 回调函数的线程执行空间
dll 与 exe 之间的通讯方式有很多种, 本文采用回调函数的方法实现, 本文也将研究多线程,多模块的情况下,回调函数所在的线程, 啥也不说了,先附上代码: 下面的是dll模块的的, dll的工程文 ...
- Ibatis入门基本语法(转) good
Ibatis入门基本语法 一个项目中在写ibatis中的sql语句时,where user_id in (#user_id_list# ), 运行时总是不行,后来上网查了查,才知道这里不该用#,而应该 ...
- uva 10651 - Pebble Solitaire(记忆化搜索)
题目链接:10651 - Pebble Solitaire 题目大意:给出一个12格的棋盘,‘o'代表摆放棋子,’-‘代表没有棋子, 当满足’-oo'时, 最右边的棋子可以跳到最左边的位子,而中间的棋 ...
- 谁动了我的CurrentPrincipal?解释一下为什么CurrentPrincipal变了,并解决这个问题。
在上一篇博客中我遇到了一个问题,并且导致了我无法继续进行授权和验证.经过查阅资料和解决另外一个问题的过程,我突然想通了为什么CurrentPrincipal变了.并且经过验证后的确是我所理解的那样.下 ...
- Oracle存储包存储及案例
Package左侧文件: create or replace package S02_ZFRZPT_YS_MID is procedure start_cal(strgranularity in va ...
- asp.net使用unescape读取js escape编码过的字符串
escape() 是JavaScript的编码函数 例子:var esstring=escape("helloworld"); 为了防止数据传输读取中出现乱码现象,字符串往往要用J ...
- C#直接插入排序
以Int类型数组为举例 namespace 直接插入排序 { class Program { private static void Insert(int[] arrayList) { bool is ...
- c++实现二分查找
简要描述: 二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好:其缺点是要求待查表为有序表,且插入删除 困难. 条件:查找的数组必须要为有序数组. 二分查找的过程剩简要描述如下图: 二种实 ...
- Nginx简单操作
Nginx简单操作 平滑重启:读取配置文件,正确后启动新nginx,关闭旧服务进程 # kill HUP nginx.pid # /usr/sbin/nginx -c /etc/nginx/nginx ...
- chrome developer tool 调试技巧2
我大概是从 08.09 年从 Firebug 转入 Chrome Developer Tool,一直用到现在,越用越喜欢.我平时调错时常用的功能有: 代码格式化可以将被压缩的代码自动展开 实时代码编辑 ...