UVa11988-破损的键盘 Broken Keyboard

题目描述

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). The size of input file does not exceed 5MB.

Output

For each case, print the Beiju text on the screen.

Sample Input

This_is_a_[Beiju]_text

[[]][][]Happy_Birthday_to_Tsinghua_University

Output for the Sample Input

BeijuThis_is_a__text

Happy_Birthday_to_Tsinghua_University

分析

终于搞懂了链表的用法...之前还是觉得很难。

又是证明了这点读程序需要异常强大的耐心...反复的读,写出步骤,画出示意图,意思也就出来了。

代码

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 using namespace std;
 5 const int maxn=100000+5;
 6 int last,cur,next[maxn];
 7 char s[maxn];
 8 int main()
 9 {
10     while(cin>>s+1)//(scanf("%s",s+1)==1)
11     {
12
13         int n=strlen(s+1);
14         /*for(int i=0;i<n;i++)
15         {
16             cout<<s[i]<<" ";
17         }*/
18         last=cur=0;
19         next[0]=0;
20         for(int i=1;i<=n;i++)
21         {
22             char ch=s[i];
23             if(ch==‘[‘)cur=0;
24             else if(ch==‘]‘)cur=last;
25             else{
26                 next[i]=next[cur];
27                 next[cur]=i;
28                 if(cur==last) last=i;
29                 cur=i;
30             }
31         }
32         for(int i=next[0];i!=0;i=next[i])
33         cout<<s[i];
34         cout<<endl;
35     }
36     return 0;
37  } 
时间: 2024-10-12 00:50:59

UVa11988-破损的键盘 Broken Keyboard的相关文章

D - 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 iss

UVa11988 Broken Keyboard(悲剧文本)

UVa11988 Broken Keyboard(悲剧文本) 题目链接:UVa11988 题目描述: 输入包含多组数据,每组数据占一行,包含不超过100000个字母.下划线.字符"["或者"]".其中字符"["表示Home键,"]"表示End键.输入结束标志为文件结束符(EOF)输入文件不超过5MB,对于每组数据,输出一行,即屏幕上的悲剧文本 样例输入: This_is_a_[Beiju]_text [[]][]Happy_B

UVA11988 Broken Keyboard (a.k.a. Beiju Text)【数组模拟链表】

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 (inter

UVa11988:Broken Keyboard

Description Broken KeyboardYou'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 gets automatically pressed (internally). You're not aware of this iss

Uva11988 Broken Keyboard (a.k.a. Beiju Text)(就是先输出括号的字符)

Description 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 with the keyboard is that sometimes the "home" key or the "end" key gets automa

UVA11988 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 it's not so badly broken. The only problem with the keyboard is that sometimes the "home" key or the "end" key gets a

11988 - Broken Keyboard (a.k.a. Beiju Text)

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 (inter

Broken Keyboard (a.k.a. Beiju Text) UVA, 11988(链表)

Broken Keyboard (a.k.a. Beiju Text) From:UVA, 11988 Time Limit: 1000 MS 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 "hom

UVa 11988 Broken Keyboard(模拟链表)

题意  有一个键盘坏了  会在你不知道的情况下按下home或者end  给你这个键盘的实际输入  要求输出显示器上的实际显示 输入最大5MB  所以直接数组检索肯定会超时的  用数组模拟链表  就可以很快了 #include<cstdio> #include<cstring> using namespace std; const int N=100005; char s[N]; int next[N]; int main() { int last,cur; while(~scanf