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).
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(模拟数组或者双重链表的运用)的更多相关文章
- 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 ...
- UVa 11998 Broken Keyboard (数组模拟链表问题)
题目链接: 传送门 Broken Keyboard #include<bits/stdc++.h> using namespace std; char str[100010]; int m ...
- UVA11988-Broken Keyboard(数组模拟链表)
Problem UVA11988-Broken Keyboard Accept: 5642 Submit: 34937 Time Limit: 1000 mSec Problem Descripti ...
- UVa 11988 Broken Keyboard(链表->数组实现)
/*数组形式描述链表:链表不一定要用指针. 题目链接:UVa 11988 Broken Keyboard 题目大意: 小明没有开屏幕输入一个字符串,电脑键盘出现了问题会不定时的录入 home end ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...
- 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 ...
- 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 ...
- 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:% ...
- 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 ...
随机推荐
- 流量分析系统---flume(测试flume+kafka)
1.在flume官方网站下载最新的flume wget http://124.205.69.169/files/A1540000011ED5DB/mirror.bit.edu.cn/apach ...
- 【转】Linux下查看进程打开的文件句柄数
---查看系统默认的最大文件句柄数,系统默认是1024 # ulimit -n 1024 ----查看当前进程打开了多少句柄数 # lsof -n|awk '{print $2}'|sort|uniq ...
- UIPageControl修改圆点大小,根据View大小自适应
遇到了个基本的控件问题,当设置UIPageControl的frame很小时,上面的小圆点会忽视view的frame而将圆点显示到控件外面. 但是如果想要设置小一点的圆点,或改变圆点间的间距,从而实现自 ...
- 028_MapReduce中的计数器Counter的使用
一.分析运行wordcount程序屏幕上打印信息 ##运行wordcount单词频率统计程序,基于输出输出路径. [hadoop@hadoop-master hadoop-1.2.1]$ hadoop ...
- qnx 黑莓系统
qnx 黑莓图形系统框架 http://www.360doc.com/content/07/0807/10/38907_658192.shtml http://blog.csdn.net/keyboa ...
- SOA 面向服务架构 阅读笔记(五)
14 SOA 服务管理器 契约:契约中必须明确定义双方的责任,否则就会产生混乱. SOA可以管理端到端的流程. IT技术一直是与业务对齐的. 14.1.1 分解IT层 业务服务层 管道层 硬件层 管道 ...
- scp 和 pscp
今天在做项目遇到了两个问题,做一些总结. 1.在项目中,防火墙的的相关配置是关于cisco企业级防火墙的配置,并不是window防火墙. 2. 在Linux上, scp linux文件 ...
- redis 第一篇
一.redis简介 redis是一个开源的高性能键值对数据库:本质上是数据结构服务器或者是数据结构数据库 特点: 1.共享内存 如果有自己的线程可以读list,如果外界还有一个程序都上面的list,那 ...
- java基础之final/static/static final
一.final 1.final修饰变量(常量) final修饰的成员变量表示常量,一旦给定初值既无法改变 2.final方法 final修饰方法,表示该方法不能被子类重写 好处:比非final方法要快 ...
- java连接SQL数据库(JDBC)相关设置
2016-06-14 一.SQL server中的相关设置(以sql server 2012 版本为例) 建立一个SQL server 身份认证的服务器登录名 首先启动SQL客户端,以windows身 ...