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 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). The size of input file does not exceed 5MB.
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
题意
每次把“[”和"]"里面的东西放到最前面
题解
正常暴力不用考虑,TLE
数组操作的就不说了,这是用链表做的
代码
#include<bits/stdc++.h>
using namespace std;
struct node
{
char data;
struct node *next;
};
int main()
{
char s[];
while(scanf("%s",s)!=EOF)
{
node *head=(node*)malloc(sizeof(node)),*rear,*p;
head->next=NULL;
p=rear=head;//第一个对头操作
for(int i=;s[i];i++)
{
char ch=s[i];
if(ch=='[')
p=head;
else if(ch==']')
p=rear;
else
{
node *q=(node*)malloc(sizeof(node));
q->data=ch;
q->next=p->next;
p->next=q;
if(p==rear)
rear=q;
p=q;
}
}
p=head->next;
while(p)
{
printf("%c",p->data);
p=p->next;
}
printf("\n");
}
return ;
}
UVa 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)的更多相关文章
- 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 ...
- 链表 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)
题目传送门 题意:训练指南P244 分析:链表模拟,维护链表的head和tail指针 #include <bits/stdc++.h> using namespace std; const ...
- UVa 11988 Broken Keyboard (a.k.a. Beiju Text)
题目复制太麻烦了,甩个链接 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18693 直接模拟光标操作时间复杂度较高,所以用链 ...
- 暑假集训单切赛第二场 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(字符串处理)
一开始不懂啊,什么Home键,什么End键,还以为相当于括号,[]里的东西先打印出来呢.后来果断百度了一下. 悲催啊... 题意:给定一个字符串,内部含有'['和']'光标转移指令,'['代表光标移向 ...
- UVa 11988 - Broken Keyboard (a.k.a. Beiju Text) 题解
刘汝佳的题目,悲剧文本 -_-||| 这里使用vector<string>容器倒置记录数据,然后从后面输出就能够了. 难度就是不知道这种文档究竟哪里是開始输出,故此使用动态管理内存的容器比 ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)
使用list来模拟就行了,如果熟悉list,那么这道题真是分分钟秒掉... list是双向循环链表,插入和删除操作非常快,缺点是不能像数组一样随机按下标读取. 一下是wiki上说明的相关函数:http ...
- 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键出了问题,会不定时的按下. ...
随机推荐
- [转]清除服务器IIS缓存的常用方法
转自:http://www.rrzzw.com/jishu/IIS/39.html 转自:http://cqujsjcyj.iteye.com/blog/736624 使用IIS来开虚拟主机空间架设网 ...
- IE6 CSS高度height:100% 无效解决方法总结
原文地址:http://www.cnblogs.com/huangyong8585/archive/2013/02/05/2893058.html 上面红色部分为 height:100%; 自动拉 ...
- 【转载】Linux内存中buffer和 cached的比较
经常遇到一些刚接触Linux的新手会问内存占用怎么那么多? 在Linux中经常发现空闲内存很少,似乎所有的内存都被系统占用了,表面感觉是内存不够用了,其实不然.这是linux内存管理的一个优秀特性,在 ...
- MariaDB管理系统
MariaDB管理系统 [root@c4kaichen@163 ~]# yum install mariadb[root@c4kaichen@163 ~]# yum install -y mariad ...
- Openstack kvm win7镜像制作
本文地址http://www.cnblogs.com/tcicy/p/7790956.html 网上找了很多为openstack制作win7镜像的文章,总是不成功 自己写一下,以便大家查看. 我使用c ...
- 简单工厂法( Factory Method)
工厂方法 (Factory Method) Define an interface for creating an object ,but let subclasses decide which cl ...
- RNN循环神经网络结构
note: RNN处理有序的数据.例如一句话 一层双向的循环神经网络示意图(没有 S0' 则为单层循环): 正向循环S0 到 Si:y1的值受X1,A1以及上一层的A0影响 反向循环Si 到 S0:y ...
- uva-10047
我们考虑一个特殊情况,一个独轮车是一个圆环,独轮车靠这个圆环运动,这个圆环上涂有五个不同的颜色,如下图每个颜色段的圆心角是72度,这个圆环在MxN个方格的棋盘上运动,独轮车从棋盘中一个格子的中心点开始 ...
- C_point指针
1,关于C语言中变量的访问方式,直接访问[使用变量名直接引用,操作变量进行赋值,改变变量值等操作],间接访问--指针,一种指向变量飞, 程序对变如量的读写操作,实际是对变量所在的存储空间进行写入和取出 ...
- spring中 的MD5 加密
//对密码进行加密(不需要使用其他Md5工具 .spring中有 在digestUtils) String password = DigestUtils.md5DigestAsHex( ...