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

破碎的键盘,之前的c语言作业,当时就没过,然后一开始想用vector,但是这个插入不行,会T,然后用链表写了一下。。吐血,不知道为什么也会T;

会T的链表代码

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
//#define pb push_back
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
//#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod=1e9+100;
const db e=exp(1);
using namespace std;
const double pi=acos(-1.0);
char a[100005];
struct node
{
char c;
node *next;
};
int main()
{
int x;
while(~sf("%s",&a))
{
node *head,*now,*last,*p;
head=new node;
int temp=0;
last=now=head;
head->next =NULL;
rep(i,0,strlen(a))
{
if(a[i]=='[')
{
now=head;
temp=1;
}
else if(a[i]==']')
{
now=last;
temp=0;
}
else
{
p=new node;
p->c =a[i];
p->next=now->next ;
now->next =p;
now=p;
if(temp==0)
last=now;
while(last->next!=NULL) last=last->next;
}
}
last->next =NULL;
p=head->next;
while(p!=NULL)
{
pf("%c",p->c);
now=p;
p=p->next;
free(now);
}
pf("\n");
}
return 0; }

后面看到刘汝佳书上有讲这题,然后照着这种方法过了p143,用数组模拟链表,因为是从左到右的,所以可以只用一个NEXT数组储存右边跟着的字符的下表就好了;

AC的

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
//#define pb push_back
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
//#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod=1e9+100;
const db e=exp(1);
using namespace std;
const double pi=acos(-1.0);
char s[100005];
int NEXT[100005],last,cur;
int main()
{
int n,last,cur; while(sf("%s",s+1)!=EOF)
{
n=strlen(s+1);
last=cur=0;
NEXT[0]=0;
for(int i=1;i<=n;i++)
{
if(s[i]=='[')
cur=0;
else if(s[i]==']')
cur=last;
else
{
NEXT[i]=NEXT[cur];
NEXT[cur]=i;
if(cur==last) last=i;
cur=i;
}
}
for(int i=NEXT[0];i!=0;i=NEXT[i])
pf("%c",s[i]);
pf("\n");
}
return 0;
}

B - Broken Keyboard (a.k.a. Beiju Text) 数组模拟链表的更多相关文章

  1. 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 ...

  2. 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 i ...

  3. 破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)

    破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988) 题意描述 你在输入文章的时候,键盘上的Home键和End键出了问题,会不定时的按下. ...

  4. 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:% ...

  5. 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 ...

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

    题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. javascript删除数组,索引出现问题解决办法。

    var data = [ { isRemove: 0, name: "项目1" }, { isRemove: 1, name: "项目2" }, { isRem ...

  2. Android性能优化-App后台优化

    原文链接 Background Optimizations 前言 后台进程是内存和电池敏感的.一个隐式的broadcast可能会启动很多监听它的后台进程,即使这些进程可能做得工作不多.这可能丢设备性能 ...

  3. git的使用笔记

    1.git下载:https://git-scm.com/downloads   安装git   2.在github.com网站上注册账号 网址:https://github.com/   3.使用gi ...

  4. Win10更新搜狗输入法后重启输入密码蓝屏

    解决办法:如果能进入安全模式,卸载搜狗输入法:不行的话(好像不行)只能重装系统:因为蓝屏后就基本开不了了!!!生气!! win10 1809 19.3月累积更新之后蓝屏:安装了搜狗输入法的win10 ...

  5. ROS actionlib学习(三)

    下面这个例子将展示用actionlib来计算随机变量的均值和标准差.首先在action文件中定义goal.result和feedback的数据类型,其中goal为样本容量,result为均值和标准差, ...

  6. 如何永久删除git仓库中敏感文件的提交记录

    如何永久删除git仓库中敏感文件的提交记录 参考: 1. https://help.github.com/articles/remove-sensitive-data/

  7. Effective Java 第三版——48. 谨慎使用流并行

    Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...

  8. 实战c++中的vector系列--vector&lt;unique_ptr&lt;&gt;&gt;初始化(全部权转移)

    C++11为我们提供了智能指针,给我们带来了非常多便利的地方. 那么假设把unique_ptr作为vector容器的元素呢? 形式如出一辙:vector<unique_ptr<int> ...

  9. Linux系统命令缩写

    命令缩写:(转) ls:list(列出目录内容) cd:Change Directory(改变目录) su:switch user 切换用户 rpm:redhat package manager 红帽 ...

  10. [Big Data - ZooKeeper] ZooKeeper: A Distributed Coordination Service for Distributed Applications

    ZooKeeper ZooKeeper: A Distributed Coordination Service for Distributed Applications Design Goals Da ...