首页 > 代码库 > Broken Keyboard (a.k.a. Beiju Text)
Broken Keyboard (a.k.a. Beiju Text)
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<set> #include<vector> #include<stack> #include<queue> #include<algorithm> #include<cstdio> #include<algorithm> #include<functional> #include<sstream> using namespace std; #define N 100005 char a[N]; int nest[N]; char ans[N]; int main() { int i, j, len; while (cin >> a) { int k, cur, last; k = cur = last = 0; nest[0] = -1; for (i = 0; a[i]; i++) { if (a[i] == ‘[‘) cur = 0; else if (a[i] == ‘]‘) cur = last; else { k++; ans[k] = a[i]; nest[k] = nest[cur]; nest[cur] = k; cur = k; if (nest[k] == -1) last = k; } } int t = nest[0]; while (t != -1) { printf("%c", ans[t]); t = nest[t]; } printf("\n"); } return 0; }
数组模拟链表
Broken Keyboard (a.k.a. Beiju Text)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。