这题我是大写的服气,辛辛苦苦搞了个双重链表结果还一直不对,不对就算了,书上源代码打进去还是不对,我能怎么办我也很无奈。不过这题还是让我对双重链表更加了解和运用了!还是可以的!

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

附上我的代码加正确答案

 #include<iostream>
#include<set>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct date
{
char ch;
date *next;
};
class myqueue
{
public: date *top,*tail,*mid;
myqueue()
{
top=NULL;
tail=NULL;
}
void inserts(char x)
{
date *p;
p=new date;
p->ch=x;
p->next=NULL;
if(top==NULL)
{
top=p;
tail=p;
}
else
{
tail->next=p;
tail=p; }
}
void insertm(char x)
{ date *p;
p=new date;
p->ch=x;
p->next=mid->next;
mid->next=p;
mid=p;
}
void insertq(char x)
{ date *p;
p=new date;
p->ch=x;
p->next=NULL;
if(top==NULL)
{
top=p;
tail=p; }
else
{
p->next=top;
top=p; }
mid=top;
}
void clears()
{
top=tail=NULL;
}
void print()
{
date *p=top;
while(p!=NULL)
{
cout<<p->ch;
p=p->next; }
} };
int main()
{
char x[];
myqueue s;
while(cin>>x)
{
s.clears();
int flag=;
int len=strlen(x);
for(int i=;i<len;i++)
{
if(x[i]=='[')
flag=;
else if(x[i]==']')
flag=;
else
{
if(flag==)
s.inserts(x[i]);
else if(flag==)
{
s.insertq(x[i]);
flag=;
}
else if(flag==)
s.insertm(x[i]); } }
s.print();
cout<<endl; } return ; }
 #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define N 100005
int main()
{
char s[N];
int last,cur,next[N];
while(scanf("%s",s+)==)
{
int n=strlen(s+);
last=cur=;
next[]=;
for(int i=;i<=n;i++)
{
char ch=s[i];
if(ch=='[')
cur=;
else if(ch==']')
cur=last;
else
{
next[i]=next[cur];
next[cur]=i;
if(cur==last)
last=i;
cur=i;
}
}
for(int i=next[];i!=;i=next[i])
printf("%c",s[i]);
printf("\n");
}
return ;
}

Broken Keyboard(模拟数组或者双重链表的运用)的更多相关文章

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

  2. UVa 11998 Broken Keyboard (数组模拟链表问题)

    题目链接: 传送门 Broken Keyboard #include<bits/stdc++.h> using namespace std; char str[100010]; int m ...

  3. UVA11988-Broken Keyboard(数组模拟链表)

    Problem UVA11988-Broken Keyboard Accept: 5642  Submit: 34937 Time Limit: 1000 mSec Problem Descripti ...

  4. UVa 11988 Broken Keyboard(链表->数组实现)

    /*数组形式描述链表:链表不一定要用指针. 题目链接:UVa 11988 Broken Keyboard 题目大意: 小明没有开屏幕输入一个字符串,电脑键盘出现了问题会不定时的录入 home end ...

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

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

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

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

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

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

随机推荐

  1. PsySH——PHP交互式控制台

    PsySH PsySH is a runtime developer console, interactive debugger and REPL for PHP. PsySH是一个PHP的运行时开发 ...

  2. 根据GUID获取设备信息

    #include <windows.h> #include <setupapi.h> #include <objbase.h> #include <initg ...

  3. pppoe白皮书

    转:https://blog.csdn.net/achejq/article/details/19478811 PPPoE技术白皮书 关键词:PPP,Ethernet,PPPoE 摘    要:PPP ...

  4. @MarkFan 口语练习录音 20140423 [风雨哈佛路.Homeless To Harvard口语录音]

    世界在转动,你只是一粒尘埃 没有你,世界照样在转 现实不会按照你的意识去改变的 一些人的需求 一些人的意志要比你更强 严酷的生活会让人不知所措 所以他们久久地困在挫败中 我们生气地抱怨,而对整体的形势 ...

  5. winter 2018 02 01 关于模运算的一道题

    题目:给出一个正整数n,问是否存在x,满足条件2^x mod n=1,如果存在,求出x的最小值. 分析:1.若给出的n是1,则肯定不存在这样的x;     2.若给出的是偶数,2的次幂取余一个偶数得到 ...

  6. char,uchar,0xff

    如果:char test = 0xFF: 此时:test != 0xFF://因为test为char类型,0xFF为int,所以编译器会将test转为int(-1),所以不等于 如果:uchar te ...

  7. 一元多项式的乘法与加法运算 【STL-map哈希-map反向迭代器遍历 + 零多项式】

    设计函数分别求两个一元多项式的乘积与和. 输入格式: 输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数).数字间以空格分隔. ...

  8. 3.django连接mysql数据库及安装mysqldb驱动报错解决办法

    1.在setting.py设置连接数据库 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'djang ...

  9. Freemarker中大于号>的使用

    在Freemarker中,比较数据的大小时候,要注意大于号(>)的使用.如果不注意,程序就会发生异常信息,如下面的例子:   1 2 3 4 <#assign x = 4> < ...

  10. 【bzoj2815】灾难[ZJOI2012](拓扑排序+lca)

    题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2815 原版题解:http://fanhq666.blog.163.com/blog/st ...