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

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. Redis慢查询,redis-cli,redis-benchmark,info

    一.慢查询: 1.慢查询的作用:通过慢查询分析,找到有问题的命令进行优化. 2.慢查询的redis的配置参数: slowlog-log-slower-than 慢查询预设阈值(单位是微秒1秒=1000 ...

  2. Spring_HelloWord

    环境:IntelliJ 14 : jdk1.8   Spring操作步骤 1.新建项目---Spring Batch 2.IntelliJ会自动加载jar包 3.现在就可以在src目录下写Java类文 ...

  3. vi的搜索和替换

    搜索中进行替换 /which #搜索which cwthat #替换成that n #重复搜索 . #重复替换 一种类型的替换命令 g/pattern/s/old/new/g 第一个 g 表示是有选择 ...

  4. OpenSSL for Android

    http://blog.csdn.net/xiongmc/article/details/25736041 OpenSSL1)开源项目Guardian Project试图让Android手机也拥有类似 ...

  5. MongoDB 使用Limit和Skip完成分页 和游标(二)

    //$slice操作符返回文档中指定数组的内部值 //查询出Jim书架中第2~4本书 db.persons.find({name:"jim"},{books:{"$sli ...

  6. OLTP和OLAP浅析

    数据库设计的一个根基就是要弄清楚数据库的类型.   当今的数据处理大致可以分成两大类:联机事务处理OLTP(on-line transaction processing在线事务处理,联机事务处理).联 ...

  7. android开发之如何将一般应用变身系统级应用【转】

    本文转载自:https://blog.csdn.net/zanelove/article/details/43953743 前提: ROOT过的手机 1,把代码编写好后,打包导出apk,copy到手机 ...

  8. 记Outlook插件与Web页面交互的各种坑 (含c# HttpWebRequest 连接https 的完美解决方法)

    1) 方案一,  使用Web Service  基础功能没问题, 只是在连接https (ssh) 网站时, 需要针对https进行开发 (即http 和https 生成两套接口, 不太容易统一 ). ...

  9. poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】

                                                                                                         ...

  10. rollingstyle in log4net

    https://stackoverflow.com/questions/734963/log4net-rollingfileappender-with-composite-rolling-style- ...