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 ...
随机推荐
- OS面试题(转载)
转载自:http://placement.freshersworld.com/power-preparation/technical-interview-preparation/os-intervie ...
- Revit对齐工具之多重对齐
Revit对齐工具用来将一个或多个图元与选定图元对齐,比如建筑建筑时可以将梁.墙.柱等对齐到轴网,或者其它类似的图元的对齐,可以对齐同一类型的图元,或者不同类型族间的对齐,可以在二维视图.立面视图和三 ...
- (转)Unity3D - 动作动画忽略timeScale
转自:http://blog.csdn.net/ynnmnm/article/details/46866347 最近在调战斗时的动画与特效,Unity3D对加/减速提供了Time.timeScale支 ...
- how to use boost program options
From: http://www.radmangames.com/programming/how-to-use-boost-program_options If it so happens that ...
- 拯救者y720 双显卡, nvidia 1060 ,Ubuntu16.04 安装 Nvidia 显卡驱动
为了能够记录,下次可以有参考的东西,就记录如此 多谢网上大牛的帖子,我都是安装您们的才顺利的一次性,无黑屏现象的完成了安装 1. 参考: 1.secure boot option ( 开机进入bios ...
- Android 使用WebView加载含有Canvas的页面截屏处理
无法截屏主要原因是webview渲染方式所导致:只需要AndroidManifest.xml中设置属性Android:hardwareAccelerated=”false”.
- MUI class="mui-switch"开关 JQuery 控制开关
<div class="mui-switch mui-active"> <div class="mui-switch-handle">& ...
- MySQL -- Innodb中的change buffer
change buffer是一种特殊的数据结构,当要修改的辅助索引页不在buffer pool中时,用来cache对辅助索引页的修改.对辅助索引页的操作可能是insert.update和delete操 ...
- [剑指Offer]5.二维数组中的查找
题目 在一个二维数组中,每一行都依照从左到右递增的顺序排序,每一列都依照从上到下递增的顺序排序.请完毕一个函数,输入这种一个二维数组和一个整数.推断数组中是否含有该整数. 思路 [算法系列之三十三]杨 ...
- 相关系数(CORRELATION COEFFICIENTS)会骗人?
CORRELATION COEFFICIENTS We've discussed how to summarize a single variable. The next question is ho ...