#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;
}
用next[i]表示当前显示屏中s[i]右边的字符编号
uva11988 broken keyboard
最新推荐文章于 2021-04-22 11:31:34 发布
本文详细解析了一段使用C++实现的代码,该代码通过读取输入字符串并根据特定规则更新显示屏的状态来实现字符串处理。通过循环遍历字符串中的字符,代码实现了对'['和']'的特殊处理,以及对其他字符的常规处理,最终通过'next'数组记录了每个字符右侧字符的位置,以实现高效的状态更新。
238

被折叠的 条评论
为什么被折叠?



