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 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) 数组模拟链表的更多相关文章
- 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 ...
- 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 ...
- 破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)
破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988) 题意描述 你在输入文章的时候,键盘上的Home键和End键出了问题,会不定时的按下. ...
- 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:% ...
- 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 ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 修改文件夹的protection level之后,哪个job会来执行re-stripe的操作呢?
有下面的一些job可能参与其中的,他们的描述如下: AutoBalance,AutoBalanceLin - Balances free space in the cluster. The goal ...
- Spark2.2+ES6.4.2(三十二):ES API之index的create/update/delete/open/close(创建index时设置setting,并创建index后根据avro模板动态设置index的mapping)
要想通过ES API对es的操作,必须获取到TransportClient对象,让后根据TransportClient获取到IndicesAdminClient对象后,方可以根据IndicesAdmi ...
- DNS的域名的解析解决办法(openDNS)
http://www.williamlong.info/archives/1101.html
- Oracle只读用户角色的建立
授予某模式下对象读权限给角色,就可以建立Oracle只读用户角色,下文对该方法的实现步骤作了详细的介绍,供您参考学习. 下面为您介绍的是Oracle只读用户角色的建立方法,该方法供您参考,如果您在Or ...
- NPM慢怎么办 - nrm切换资源镜像
1. 直接配置为taobao镜像 npm config set registry https://registry.npm.taobao.org 1. 使用NRM管理镜像 npm isntall -g ...
- 基于Python项目的Redis缓存消耗内存数据简单分析(附详细操作步骤)
目录 1 准备工作 2 具体实施 1 准备工作 什么是Redis? Redis:一个高性能的key-value数据库.支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使 ...
- SNF快速开发平台MVC-富文本控件集成了百度开源项目editor
一.效果如下: 二.在框架当中调用代码如下: 1.在js里配置如下: <script type="text/javascript"> var viewModel =fu ...
- Apache Spark 2.2.0 新特性详细介绍
本章内容: 待整理 参考文献: Apache Spark 2.2.0新特性详细介绍 Introducing Apache Spark 2.2
- FOR XML PATH 可以将查询结果根据行输出成XML格式
SELECT CAST(OrderID AS varchar)+',' as OrderNo FROM Product CAST函数用于将某种数据类型的表达式显式转换为另一种数据类型 SELECT C ...
- 【6集iCore3_ADP触摸屏驱动讲解视频】6-4 底层驱动之SDRAM读写(上)
源视频包下载地址: 链接:http://pan.baidu.com/s/1i5lzzj3 密码:bwoe 银杏科技优酷视频发布区: http://i.youku.com/gingko8