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 ...
随机推荐
- Mecanim动画模型规范
面数控制, 以三角面计算 不要超过4边的面 光滑组,法线 单位CM,单位比例 中心点 3DMax:Reset Transform Maya:Freeze Transformation 帧率:30帧 不 ...
- 我的第一个DMZ方案实践
方案提出的初衷:外网需要定时和不定时推送数据到内网服务器(只要求数据到达内网,没有要求直接连接到内网) 为什么不是直连到内网:每个人第一想到的是不安全,是的,没错不安全.内网的应用和外网的应用最明显的 ...
- 类似掌盟的Tab页 Android 开源框架ViewPageIndicator 和 ViewPager 仿网易新闻客户端Tab标签 (转)
原博客地址 :http://blog.csdn.net/xiaanming/article/details/10766053 本文转载,记录学习用,如有需要,请到原作者网站查看(上面这个网址) 之前 ...
- iOS开发--二维码的扫描
一.需要包含头文件 #import <AVFoundation/AVFoundation.h> 二.通过设置<AVCaptureMetadataOutputObjectsDelega ...
- JAVA System.getProperty() 与 System.getenv() 差异及示例
System.getenv() 方法是获取指定的环境变量的值. System.getenv() 接收参数为任意字符串,当存在指定环境变量时即返回环境变量的值,否则返回null. System.getP ...
- word2007插入页码里面不显示或没选项可点怎么办?
1.打开Word 2007 2.单击Microsoft Office按钮 (左上角的圆圈) 3.单击“Word 选项”(在页面的右下方) 4.单击“加载”项(页面左边一排,倒数第三个,出现的页面中,向 ...
- python 进程间共享数据 (二)
Python中进程间共享数据,除了基本的queue,pipe和value+array外,还提供了更高层次的封装.使用multiprocessing.Manager可以简单地使用这些高级接口. Mana ...
- Jquery.min.js 下载
Jquery 下载:http://www.jq22.com/jquery-info122
- 100803C
画个图,很容易发现少兜圈子,就是说这些限制c[i],d[i]可以看做[c[i],d[i]],不让那些区间相交,然后就可以了 #include<iostream> #include<c ...
- HTML-图片热点、网页内嵌、网页拼接、快速切图
图片热点 规划出图片上的一个区域,可以做出超链接,直接点击图片区域就可以完成跳转的效果.与图片链接不同,热点是图片上的某一个区域或多个区域. 我们用魔兽世界图片来做一个图片热点,点击logo.区域和不 ...