UVa 11998 Broken Keyboard (数组模拟链表问题)
题目链接: 传送门
Broken Keyboard
#include<bits/stdc++.h>
using namespace std;
char str[100010];
int main()
{
while(scanf("%s",str)!=EOF)
{
deque<int > q;
int i=0;
while(str[i]=='['||str[i]==']') i++;
q.push_front(i);
while(str[i])
{
if(str[i]=='[')
{
q.push_front(i+1);
str[i]='\0';
}
else if(str[i]==']')
{
q.push_back(i+1);
str[i]='\0';
}
i++;
}
while(!q.empty())
{
printf("%s",str+q.front());
q.pop_front();
}
printf("\n");
}
return 0;
}
刘汝佳版
// UVa11988 Broken Keyboard
// Rujia Liu
#include<cstdio>
#include<cstring>
const int maxn = 100000 + 5;
int last, cur, next[maxn]; // 光标位于cur号字符的后面
char s[maxn];
int main()
{
while(scanf("%s", s+1) == 1)
{
int n = strlen(s+1); // 输入保存在s[1], s[2]...中
last = cur = 0;
next[0] = 0;
for(int i = 1; i <= n; i++)
{
char ch = s[i];
if(ch == '[')
{
cur = 0;
}
else if(ch == ']')
{
cur = last;
}
else
{
next[i] = next[cur];
next[cur] = i;
if(cur == last) // 更新“最后一个字符”编号
{
last = i;
}
cur = i; // 移动光标
}
}
for(int i = next[0]; i != 0; i = next[i])
printf("%c", s[i]);
printf("\n");
}
return 0;
}
UVa 11998 Broken Keyboard (数组模拟链表问题)的更多相关文章
- UVa 11988 Broken Keyboard(数组模拟链表)
题目链接: https://cn.vjudge.net/problem/UVA-11988 /* 问题 将一段文本经过一定的规则处理后输出,规则就是[表示home键,表示光标跳到行首,]表示end键, ...
- UVa 11988 Broken Keyboard(链表->数组实现)
/*数组形式描述链表:链表不一定要用指针. 题目链接:UVa 11988 Broken Keyboard 题目大意: 小明没有开屏幕输入一个字符串,电脑键盘出现了问题会不定时的录入 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 ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...
- UVA11988-Broken Keyboard(数组模拟链表)
Problem UVA11988-Broken Keyboard Accept: 5642 Submit: 34937 Time Limit: 1000 mSec Problem Descripti ...
- Uva 11988 Broken Keyboard STL+链表
两种方法,直接上代码 STL标准模板库 #include <iostream> #include <list> #include <algorithm> #incl ...
- 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 ...
随机推荐
- Mininet在创建拓扑的过程中为什么不打印信息了——了解Mininet的log系统
前言 写这篇博客是为了给我的愚蠢和浪费的6个小时买单! 过程原因分析 我用Mininet创建过不少拓扑了,这次创建的拓扑非常简单,如下图,创建拓扑的代码见github.在以前的拓扑创建过程中,我都是用 ...
- ASP.NET - SqlSugar ORM框架 更新列表
以后SqlSugar所有更新都会在这个贴子更新 SqlSugar是一款轻量级的MSSQL ORM ,除了具有媲美ADO的性能外还具有和EF相似简单易用的语法. 学习列表 0.功能更新 1.SqlSug ...
- bat批处理文件启动Eclipse和ivy本地仓库的配置
一.bat批处理文件启动Eclipse 所需文件: 1.eclipse 2.jre 3.startup-eclipse.bat 确保以上三个文件夹同级 startup-eclipse.bat: set ...
- 【摘抄】将xml注释文档生成网页
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath(&quo ...
- android 一条线
还在为布局的时候做不出来一条细细的线而烦恼么? 哈哈,自从知道了写法腰也不酸了,腿也不疼了!一口气写100行!! <View android:layout_height="1px&qu ...
- alpha版本冲刺总结
小组:The Expendables 一.项目预期计划 1.基本完成所有界面设计 2.基本完成所有功能设计(导入导出excel表格,搜索功能,文件选择功能,连接服务器等...) 3.基本完成服务器搭建 ...
- “Ceph浅析”系列之二——Ceph概况
本文将对Ceph的基本情况进行概要介绍,以期读者能够在不涉及技术细节的情况下对Ceph建立一个初步印象. 1. 什么是Ceph? Ceph的官方网站Ceph.com上用如下这句话简明扼要地定义了Cep ...
- 在Ubuntu 14.04安装Nginx
###介绍 Nginx是世界上最流行的网络服务器中的一种,负责托管网络上一些流量最高的网站.在多数情况下,Nginx比Apache在资源上更加友好,可以作为网络服务器或反向代理服务器. 这篇教程中,我 ...
- Swift开发小技巧--自定义Log
Swift中的自定义Log OC中有宏的定义,可以定义自己的Log,但是Swif中没有宏的定义,想要实现类似OC中的自定义Log,必须实现以下操作 1.在AppDelegate.swift文件中定义一 ...
- js_RGB转16进制(rgb2hex)
输入:rgb(13,0,255) 输出:#0d00ff 在线颜色转换工具:http://www.atool.org/colorpicker.php 1 2 3 4 5 6 7 8 9 function ...