破损的键盘(UVa 11988)

  s[] 数组用来保存原有的字符序列

  nex[] 数组记录打印的下标顺序

C++11 代码如下:

 #include<iostream>
#include<cstring>
using namespace std;
#define maxn 100006
char s[maxn];
int nex[maxn], n; int main() {
while (cin >> s + ) {
int cur = , last = ;
nex[] = ;
char ch;
for (int i = ; i <=strlen(s + ); i++) {
ch = s[i];
if (ch == '[') cur = ;
else if (ch == ']') cur = last;
else {
nex[i] = nex[cur];
nex[cur] = i;
if (cur == last)last = i;
cur = i;
}
}
for (int i = nex[]; i != ; i = nex[i])
cout << s[i];
cout << endl;
}
return ;
}
上一篇:JAVA第一个窗体小程序


下一篇:2017 ACM-ICPC 南宁区比赛 Minimum Distance in a Star Graph