UVA - 11988 Broken Keyboard (a.k.a. Beiju Text)
来源:互联网 发布:高胡seo博客 编辑:程序博客网 时间:2024/06/06 05:54
#include <cstdio>
#include <cstring>
const int maxn = 100000 + 5;
int last, cur, next[maxn];
char s[maxn];
int main()
{
while(scanf("%s", s+1) == 1)
{
int n = strlen(s+1);
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;
#include <cstring>
const int maxn = 100000 + 5;
int last, cur, next[maxn];
char s[maxn];
int main()
{
while(scanf("%s", s+1) == 1)
{
int n = strlen(s+1);
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;
}
心得:原则上是不许把例题贴出来的,不过当我看到好的例题有很多感想时,总是忍不住来一发T T
本题是模拟链表,虽然我对链表还不熟悉。不过思考很长时间之后,发现这算法太厉害了,这TM谁想出来的啊。。。
话不多说上图,当我模拟完之后,看着428 561 90的数列很无语,但是惊奇的一刻发生了,这输出不是普通的输出!以next数组为媒介,next的值为元素,再递归调用,第一次见,原来这才是本题的核心!我读书少一惊一乍的大家看了别喷。。。
0 0
- Uva-11988-Broken Keyboard (a.k.a. Beiju Text)
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)
- uva 11988 Broken Keyboard (a.k.a. Beiju Text)
- UVA 11988 - Broken Keyboard (a.k.a. Beiju Text)
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)
- UVa:11988 Broken Keyboard (a.k.a. Beiju Text)
- UVA - 11988 Broken Keyboard (a.k.a. Beiju Text)
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)
- UVa 11988 - Broken Keyboard (a.k.a. Beiju Text) 题解
- UVA 11988 - Broken Keyboard (a.k.a. Beiju Text)
- Broken Keyboard (a.k.a. Beiju Text) UVA, 11988(链表)
- UVa 11988 - Broken Keyboard (a.k.a. Beiju Text)
- UVA - 11988 Broken Keyboard (a.k.a. Beiju Text)
- UVa 11988 - Broken Keyboard (a.k.a. Beiju Text)
- UVA - 11988 Broken Keyboard (a.k.a. Beiju Text)链表
- UVA - 11988 Broken Keyboard (a.k.a. Beiju Text) 链表
- UVA - 11988 Broken Keyboard (a.k.a. Beiju Text)
- uva 11988 Broken Keyboard (a.k.a. Beiju Text) 链表
- LeetCode 91: Decode Ways
- UIButton, 设置button的背景图片
- 有关报表服务器运行正确,但嵌入到网页中提示因 HTTP 状态 401 失败: Unauthorized。
- 面试时JDBC程序编写简洁版
- UML第二集
- UVA - 11988 Broken Keyboard (a.k.a. Beiju Text)
- POJ 2632 较复杂的模拟
- 中断与异常详解(一)
- 利用运行循环解决NSURLConnection多线程下载的问题(只需要了解)
- Supporting Multiple Screens
- • UFLDL教程练习(exercise)答案(1)
- pjsip项目概要及c语言面向对象方法实现
- Android ORM数据库框架之-greenDao(四)
- git相关操作(简单篇)