UVA11988-Broken Keyboard(数组模拟链表)
Problem UVA11988-Broken Keyboard
Accept: 5642 Submit: 34937
Time Limit: 1000 mSec
Problem Description
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
题解:第一次做这个题完全是看着紫书的代码敲的,这一次才算是真的自己做出来,其实就是数组模拟链表,但是由于我的代码能力不好的,做起来不顺。
首先是初始化的问题,Next数组全部是0,然后两个指针,一个now,一个tail前者用来表示当前应该在那个字符,后者表示已经处理过的字符串的真正的末尾。
遇到文本字符,就用链表的方式插入到now的后面,然后now到这个新加入的字符,tail更新是看Next[now]是否为0,是0就赋值tail = now.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std; const int maxn = +;
char str[maxn];
int Next[maxn]; int main()
{
//freopen("input.txt","r",stdin);
while(~scanf("%s",str+)){
int len = strlen(str+);
int now = ,tail = ;
memset(Next,,sizeof(Next));
for(int i = ;i <= len;i++){
if(str[i]!='[' && str[i]!=']'){
Next[i] = Next[now];
Next[now] = i;
now = i;
if(Next[now] == ) tail = now;
}
else if(str[i] == '[') now = ;
else{
now = tail;
}
}
int t = Next[];
while(t != ){
printf("%c",str[t]);
t = Next[t];
}
printf("\n");
}
return ;
}
UVA11988-Broken Keyboard(数组模拟链表)的更多相关文章
- UVa 11998 Broken Keyboard (数组模拟链表问题)
题目链接: 传送门 Broken Keyboard #include<bits/stdc++.h> using namespace std; char str[100010]; int m ...
- UVa 11988 Broken Keyboard(数组模拟链表)
题目链接: https://cn.vjudge.net/problem/UVA-11988 /* 问题 将一段文本经过一定的规则处理后输出,规则就是[表示home键,表示光标跳到行首,]表示end键, ...
- 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 ...
- C - Boxes in a Line 数组模拟链表
You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to simul ...
- PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)
1052 Linked List Sorting (25 分) A linked list consists of a series of structures, which are not ne ...
- Broken Keyboard(模拟数组或者双重链表的运用)
这题我是大写的服气,辛辛苦苦搞了个双重链表结果还一直不对,不对就算了,书上源代码打进去还是不对,我能怎么办我也很无奈.不过这题还是让我对双重链表更加了解和运用了!还是可以的! You’re typin ...
- UVa12657 - Boxes in a Line(数组模拟链表)
题目大意 你有一行盒子,从左到右依次编号为1, 2, 3,…, n.你可以执行四种指令: 1 X Y表示把盒子X移动到盒子Y左边(如果X已经在Y的左边则忽略此指令).2 X Y表示把盒子X移动到盒子Y ...
- UVa11988 Broken Keyboard 损坏的键盘【list】
题目链接:https://vjudge.net/problem/UVA-11988 题目大意: 键盘的home键和end键出现了问题. 在输入一段文本时,home键或end键可能会自动被按下,home ...
- 天梯赛 L2-022. (数组模拟链表) 重排链表
题目链接 题目描述 给定一个单链表 L1→L2→...→Ln-1→Ln,请编写程序将链表重新排列为 Ln→L1→Ln-1→L2→....例如:给定L为1→2→3→4→5→6,则输出应该为6→1→5→2 ...
随机推荐
- [转]Angular4 自制分页控件
本文转自:https://blog.csdn.net/Junyuan_123/article/details/79486276 过年后第一波,自制的分页控件,可能功能没有 PrimeNG 那么好,但是 ...
- Bootstrap学习记录-1.Navigation
Bootstrap中的导航栏功能需要添加bootstrap.css.jquery.js.bootstrap.js,其中,jquery.js文件是bootstrap.js文件中必须的,否则就会抛出异常信 ...
- 在visual studio中设置点击左边选项卡中的类文件,右侧解决方案跳到对应的文件
在visual studio中如何设置点击左边选项卡中的类文件,右侧解决方案跳到对应的文件?比如说,VS上方的选项卡文件较多,我点击选项卡上的任一文件,解决方案中对应的文件突出显示 ...
- Paired t-test
1 Continuous Dependent Variable with normal distribution 1 (2 Level) Categorical Independent Variabl ...
- cache 访问频率的思考
互联网的项目用户基数很大,有时候瞬间并发量非常大,这个时候对于数据访问来说是个灾难.为了应对这种场景,一般都会大量采用web服务器集群,缓存集群.采用集群后基本上就能解决大量并发的数据访问.当然这个时 ...
- PHP7.27: object
http://www.devshed.com/c/a/PHP/PHP-Services-Layers-Data-Mappers/ https://stackoverflow.com/questions ...
- mysql之数据备份与还原
mysql数据备份 #1. 物理备份: 直接复制数据库文件,适用于大型数据库环境.但不能恢复到异构系统中如Windows. #2. 逻辑备份: 备份的是建表.建库.插入等操作所执行SQL语句,适用于中 ...
- 【代码笔记】Web-HTML-图像
一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- Loadrunner 脚本开发-从文件读取数据并参数化
脚本开发-从文件读取数据并参数化 by:授客 QQ:1033553122 直接上代码: char* testfn() { int count, total = 0; //char buffer[1 ...
- Java并发编程(十四)Java内存模型
1.共享内存和消息传递 线程之间的通信机制有两种:共享内存和消息传递:在共享内存的并发模型里,线程之间共享程序的公共状态,线程之间通过写-读内存中的公共状态来隐式进行通信.在消息传递的并发模型里,线程 ...