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 ...
随机推荐
- Java 基础【09】 日期类型
java api中日期类型的继承关系 java.lang.Object --java.util.Date --java.sql.Date --java.sql.Time --java.sql.Time ...
- Redis的五种数据结构
Redis支持持久化只是它的一件武器,它提供了多达5种数据存储方式: 一 string(字符串) string是最简单的类型,你可以理解成与Memcached一模一样的类型,一个key对应一个val ...
- KM模板
var n,m,i,j:longint; ans:int64; sel,lx,ly,slack:..] of int64; a:..,..] of int64; visx,visy:..] of bo ...
- STL中algorithm里的查找
首先,选择查找算法时,区间是否排序是一个至关重要的因素.可以按是否需要排序区间分为两组: A. count,find B. binary_search,lower_bound,upper_bound, ...
- Android 强制竖屏
一般android 显示内容都有两种实现方式,java代码中实现,xml布局中实现(或者权限管理页面) 直接上代码: java方法 setRequestedOrientation(ActivityIn ...
- Beta项目冲刺 --第二天
在几kb的上传速度中苦苦挣扎的程序员... 队伍:F4 成员:031302301 毕容甲 031302302 蔡逸轩 031302430 肖阳 031302418 黄彦宁 会议内容: 1.站立式会议照 ...
- Apache Tomcat相应插件版本
参考页面: http://tomcat.apache.org/whichversion.html
- extJs学习基础3 ajax与php交互
extJs代码: <script src="build/ext-all.js"></script> <script src="build/p ...
- 延时程序执行Qt
有时候为了让程序暂停一下,不让它一直跑下去,可以使它进入循环结构中! 例如: #include <QCoreApplication> #include <qdebug.h> # ...
- JavaMelody监控SQL
前言 前面讲过了Javamelody的基本配置,这里简单的介绍下,如何使用Javamelody来监控JDBC以及SQL. 手码不易,转载请注明:xingoo 在网上搜索很多资料,仅有开源社区上的两篇帖 ...