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. 前后端分离demo 旅馆管理系统

    模型设计   旅馆管理系统,主要涉及到登记入住,退房以及客房和客人信息管理:经过分析抽像出涉及到的实体以及各实体之间的关系:   可以看出整个业务以客房为中心,入住,退房,定价,收费都是以客房为基本单 ...

  2. 基本css说明

    /*-moz代表firefox浏览器私有属性 2.-ms代表ie浏览器私有属性 3.-webkit代表safari.chrome私有属性*/ body, dl, dd, ul, ol, h1, h2, ...

  3. 数据结构-Python3.7<三>

    上一篇:流程控制-Python<二> 因为列表具有pop.append.insert方法,因此列表可以当作堆.栈使用.由于性能问题,不建议当作堆.(堆:队列优先,先进先出(FIFO—fir ...

  4. git+github/码云+VSCode (转载)

    VSCode中使用git,参见. Git安装   在初次使用时如果本地没有安装git会提示先安装git,然后重启vscode. 一.本地操作项目前提: 1)若本地没有git拉取下来的项目,用git克隆 ...

  5. 使用Maven搭建JFinal环境

    使用Maven搭建JFinal环境 工具:IDEA 2017 JFinal版本:3.4 一.Maven项目创建 选择maven模板进行创建 填写GroupId和ArtifactId 一路Next即可 ...

  6. Python全栈学习_day011作业

    1,写函数,传入n个数,返回字典{‘max’:最大值,’min’:最小值}例如:min_max(2,5,7,8,4) 返回:{‘max’:8,’min’:2}(此题用到max(),min()内置函数) ...

  7. Spark 跑 java 示例代码

    一.下载示例代码: git clone https://github.com/melphi/spark-examples.git 从示例代码中可以看到 pox中引入了 Spark开发所需要的依赖. 二 ...

  8. fetch发送Form Data请求并携带cookie

    今天我们来说说如何fetch发送Form Data请求并携带cookie,直接进入正题好吧,别问我今天为啥不在开始吹两句了,累到一句牛逼不想吹...... 步骤1: 设置头部,"Conten ...

  9. 【读书笔记】iOS-storyboard-两个场景间的切换(二)

    接着上一节 一,在storybord画布上面,新增加一个场景,即拖动一个View Controller到画布上面,同时建立一个button,名字为secondButton.如图所示. 二,点击第一个按 ...

  10. 【读书笔记】iOS-iOS安全基础知识

    一,iOS硬件/设备的类型. iPad的问世,就是在这一方向上迈出的第一步.第一代iPad使用了ARM Cortex-A8架构的CUP,它的速度大约是第一代iPhone所使用CPU速度的两倍. iPa ...