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 ...
随机推荐
- Nodejs进阶:如何玩转子进程(child_process)
本文摘录自个人总结<Nodejs学习笔记>,更多章节及更新,请访问 github主页地址.欢迎加群交流,群号 197339705. 模块概览 在node中,child_process这个模 ...
- Bootstrap系列 -- 2. 标题
一. Bootstrap标题 在Bootstrap中使用标题和Html本身没有太大的区别使用h1-h6, 而Bootstrap只是默认修改了H1-h6的样式,网上找到如下资料参考 二. Bootstr ...
- DB2和Oracle区别
转 http://blog.chinaunix.net/uid-7374279-id-2057574.html 写在前面:今天客户来访(日本人),问我DB2和Oracle区别.因为不是DBA(勉强的理 ...
- eclipse failed to load the jni jvm.dll
问题:打开Eclipse弹出,eclipse failed to load the jni jvm.dll,一般都是本机的JDK与Eclipse位数不等{32-64,64-32} 解决:看本机Java ...
- python代码缩进
习惯了java,c++之类的宽容,初学python,被它摆了道下马威,写if else,竟然必须要我正确用缩进格式,原来在python里不能用括号来表示语句块,也不能用开始/结束标志符来表示,而是靠缩 ...
- Oracle报 ORA-00054资源正忙的解决办法
来源于:http://www.cnblogs.com/loveLearning/p/3625544.html oracle之报错:ORA-00054: 资源正忙,要求指定 NOWAIT 问题如下: S ...
- LINUX 配置IP
1. 用命令查看一下IP配置:ifconfig, 修改网络配置文件 vi /etc/sysconfig/network-scripts/ifcfg-eht0 2.但是,很多时候,较难记住里面文件的 ...
- 18位身份证验证--java实现,正则表达式
简单的正则表达式: (1)preg_match("/^(\d{18,18}|\d{15,15}|\d{17,17}x)$/",$id_card)(2)preg_match(&quo ...
- 学习Spring(二) 调用静态工厂方法创建Bean
1,创建抽象的产品类 package com.robert.spring.shop; public abstract class Product { } 2,创建具体产品类 package com.r ...
- 控件 UI: StateTrigger
VisualState 之 StateTrigger 示例1.自定义 StateTriggerControls/UI/VisualState/MyDeviceFamilyStateTrigger.cs ...