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(数组模拟链表)的更多相关文章

  1. UVa 11998 Broken Keyboard (数组模拟链表问题)

    题目链接: 传送门 Broken Keyboard #include<bits/stdc++.h> using namespace std; char str[100010]; int m ...

  2. UVa 11988 Broken Keyboard(数组模拟链表)

    题目链接: https://cn.vjudge.net/problem/UVA-11988 /* 问题 将一段文本经过一定的规则处理后输出,规则就是[表示home键,表示光标跳到行首,]表示end键, ...

  3. 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 ...

  4. 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 ...

  5. PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)

    1052 Linked List Sorting (25 分)   A linked list consists of a series of structures, which are not ne ...

  6. Broken Keyboard(模拟数组或者双重链表的运用)

    这题我是大写的服气,辛辛苦苦搞了个双重链表结果还一直不对,不对就算了,书上源代码打进去还是不对,我能怎么办我也很无奈.不过这题还是让我对双重链表更加了解和运用了!还是可以的! You’re typin ...

  7. UVa12657 - Boxes in a Line(数组模拟链表)

    题目大意 你有一行盒子,从左到右依次编号为1, 2, 3,…, n.你可以执行四种指令: 1 X Y表示把盒子X移动到盒子Y左边(如果X已经在Y的左边则忽略此指令).2 X Y表示把盒子X移动到盒子Y ...

  8. UVa11988 Broken Keyboard 损坏的键盘【list】

    题目链接:https://vjudge.net/problem/UVA-11988 题目大意: 键盘的home键和end键出现了问题. 在输入一段文本时,home键或end键可能会自动被按下,home ...

  9. 天梯赛 L2-022. (数组模拟链表) 重排链表

    题目链接 题目描述 给定一个单链表 L1→L2→...→Ln-1→Ln,请编写程序将链表重新排列为 Ln→L1→Ln-1→L2→....例如:给定L为1→2→3→4→5→6,则输出应该为6→1→5→2 ...

随机推荐

  1. 4.移植uboot-使uboot支持DM9000网卡

    在上一章,使uboot能够支持nor.nand 本节继续修改让uboot支持DM9000C网卡,便可以通过网络来传输文件 首先uboot已带有dm9000网卡的驱动,位于drivers/net/下的d ...

  2. Java使用foreach语句对数组成员遍历输出

    /** * 本程序使用foreach语句对数组成员进行遍历输出 * @author Lei * @version 2018-7-23 */ public class ForeachDemo { pub ...

  3. Hash Table (youtube)

    here is a link for youtube about hash table which is super good https://www.youtube.com/watch?v=h2d9 ...

  4. CSS--使用伪选择器制作箭头图标

    // 使用Transform的属性,组合translate(位移)和rotate(旋转),将生成的小矩形组合成各种箭头样式: HTML <section class="main&quo ...

  5. Python全栈学习_day003作业

    day3作业及默写 1,有变量name = "aleX leNb" 完成如下操作: 1) 移除 name 变量对应的值两边的空格,并输出处理结果 print(name.strip( ...

  6. Vue 爬坑之路(十二)—— vue-cli 3.x 搭建项目

    Vue Cli 3 官方文档:https://cli.vuejs.org/zh/guide/ 一.安装 @vue/cli 更新到 3.x 之后,vue-cli 的包名从 vue-cli 改成了 @vu ...

  7. 【代码笔记】Web-ionic tab(选项卡)

    一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  8. android recovery升级过程中掉电处理

    一般在升级过程,都会提示用户,请勿断电,不管是android的STB,TV还是PHONE,或者是其他的终端设备,升级过程,基本上都可以看到“正在升级,请勿断电”,然后有个进度条,显示升级的进度. 但是 ...

  9. 使用spark DStream的foreachRDD时要注意哪些坑?

    答案: 两个坑, 性能坑和线程坑 DStream是抽象类,它把连续的数据流拆成很多的小RDD数据块, 这叫做“微批次”, spark的流式处理, 都是“微批次处理”. DStream内部实现上有批次处 ...

  10. ipa的plist文件查看

    1.ipa包解压缩:右键.ipa包,使用[归档实用工具/unarchiver]打开 2.进入解压缩后的payload目录,右键ipa包-显示包内容 3.找到info.plist文件,直接拖拽出来 4. ...