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 ...
随机推荐
- web测试点梳理
前言 前面一篇文章讲解了app测试一些功能点.那么相应的也梳理一下web测试相关的功能的测试点吧,此篇文章只是给你们一个思路,如果要涉及web端每个测试点,基本不可能实现的,所以只是提供一个设计的思路 ...
- HASH、HASH函数、HASH算法的通俗理解
之前经常遇到hash函数或者经常用到hash函数,但是hash到底是什么?或者hash函数到底是什么?却很少去考虑.最近同学去面试被问到这个问题,自己看文章也看到hash的问题.遂较为细致的追究了一番 ...
- libhdfs的配置和使用
测试环境:centos6.10,hadoop2.7.3,jdk1.8 测试代码:HDFSCSample.c #include "hdfs.h" #include <strin ...
- nodejs模块Phantom,无界面浏览器
PhantomJS 是一个无界面的 webkit 内核浏览器,
- dll和lib
lib:里面包含了很多源代码,工程会将这些源代码加入自己的项目中编译: dll:动态编译库,允许可执行文件在运行中加载里面的资源. 使用lib需注意两个文件:(1).h头文件,包含lib中说明输出的类 ...
- Kafaka高可用集群环境搭建
zk集群环境搭建:https://www.cnblogs.com/toov5/p/9897868.html 三台主机每台的Java版本1.8 下面kafka集群的搭建: 3台虚拟机均进行以下操作: ...
- 【P2629】好消息,坏消息(前缀和+单调队列优化DP)
一激动一颓就会忘了总结... 前面的大黄题就不总结了. 这个题我只想说一声艹,一开始的思路就是正确的,然后计算的时候有了一个瑕疵,不过很快也就改过来了.然后却一直连样例都过不了.仔仔细细看了老半天,经 ...
- 【bzoj1899】[Zjoi2004]Lunch 午餐(贪心+dp)
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1899 显然为了节省时间,吃饭慢的人要先打饭.于是我们可以先把所有人按吃饭时间排序,于是 ...
- HDFS数据完整性
数据完整性 Hadoop用户肯定都希望系统在存储和处理数据时不会丢失或损坏任何数据.尽管磁盘或网络上的每个I/O操作不太可能将错误引入自己正在读/写的数据中,但是如果系统中需要处理的数据量大到Hado ...
- Phoenix on HBase
(一)概要 Apache Phoenix是基于BSD许可开源的一个Java中间层,可以让开发者在Apache HBase上执行SQL查询.Apache Phoenix主要特性: 嵌入式的JDBC驱动, ...