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. .14-浅析webpack源码之Watchpack模块

    解决掉了最头疼的DirectoryWatcher内部实现,这一节可以结束NodeWatchFileSystem模块. 关于watch的应用场景,仔细思考了下,这不就是热重载的核心嘛. 首先是监视文件, ...

  2. Ubuntu安装与配置

    四.ubuntu下生成ngrok服务器主程序 4.1.步骤与先决条件 如果你只是临时穿透或调试用,到第三步基本就可以了,但如果想作为稳定的商业服务,用别人的服务器还是受制于人,这里我们准备搭建自己的n ...

  3. 将MySQL数据库转移到SqlServer2008数据库

    由于工作需要用到了将MySQL数据库转成SqlServer数据库,查了一些资料发现将SqlServer数据库转成MySQL数据库的文章很多,但是反过来的就很少了.下面就将自己的方法分享给大家. 这里用 ...

  4. AJAX 基本结构 数据加载

    AJAX -- 网页数据异步加载 .ashx 一般处理程序   json 数据格式,在不同的语言之间传递数据 对象格式:     "{"key":"value& ...

  5. 深入理解JVM——虚拟机GC

    对象是否存活 Java的GC基于可达性分析算法(Python用引用计数法),通过可达性分析来判定对象是否存活.这个算法的基本思想是通过一系列"GC Roots"的对象作为起始点,从 ...

  6. PDF格式的“在线阅读”和“下载”

    产生背景: 一个需求,用户可在线阅读PDF,也可下载到本地.听需求来源说人家的网站上的可以做,问我们能做吗,需要这个功能,就要来了网址,看看页面. 问题:上传PDF文件后,发现访问地址在浏览器上打开, ...

  7. webpack打包时排除其中一个css、js文件,或单独打包一个css、js文件

    在项目中经常会需要将一些接口的配合文件或者某些样式文件,分离出来单独打包,便于后期改动,这里我以css文件为例,介绍实现两种方法: 项目目录: 如上图所示,现在我需要将项目中的scBtn.css文件单 ...

  8. 图片缩放PhoneView

    第一步:导包 implementation 'com.github.chrisbanes:PhotoView:2.0.0' 第二步:加bmob仓库地址 在build.gradle(project)中的 ...

  9. OneAlert 携手 BearyChat(倍洽)快速构建 IT 运维 on-call 机制

    OneAlert 是北京蓝海讯通科技股份有限公司旗下产品,中国第⼀个 SaaS 模式的免费的云告警平台,集成国内外主流监控/⽀撑系统,实现⼀个平台上集中处理所有 IT 事件,提升 IT 可靠性.并且能 ...

  10. aws s3文件上传设置accesskey、secretkey、sessiontoken

    背景: 最近跟进的项目会封装aws S3资源管理细节,对外提供获取文件上传凭证的API,业务方使用获取到的凭证信息直接请求aws进行文件上传.因此,测试过程需要验证S3文件上传的有效性.aws官网有提 ...