小兔子乖乖,把门开开。不开不开就不开,jc没回来,嘿嘿嘿。
怀疑当时怎么学的邻接表。感觉链表还是不会用。
果然辣鸡,需要补;
先放小白(紫)代码:
#include <cstdio>
#include <queue>
#include <iostream>
#include <cstring>
using namespace std;
const int MAXN = 100010;
char s[MAXN];
int next[MAXN];
int last, cur;
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 c = s[i];
if(c == '[') // 如果出现 '[' , 那么后面的字符我们需要先输出;
cur = 0; // 使 next[0] = '[' ,后面的第一个字符的下标;
else if(c == ']') // 出 ] 时继续进括号时的 last 下标;
cur = last;
else{
next[i] = next[cur]; // next[i] = 光标后面的字符的下标;
next[cur] = i;// 赋值光标的后面的的下标;
if(cur == last) // 如果当前光标在[]里面,那么这个if不会执行,last保持原状;
last = i;
cur = i;// 不管是否在那里进行字符处理,都要进行光标的移动。
}
}
for(int i = next[0]; i != 0; i = next[i])
printf("%c", s[i]);
printf("\n");
}
return 0;
}
先来一波破损的键盘的简化过程:
A _ [ B e ] _
1 2 3 4 5 6 7
// A
cur = 0;
last = 0;
next[0] = 0;
next[1] = next[0];
next[0] = 1;
last = 1;
cur = 1;
// _
next[2] = next[1];
next[1] = 2;
last = 2;
cur = 2;
// [
cur = 0;
last = 2;
cur = 0;
// B
next[4] = next[0];
next[0] = 4;
last = 2;
cur = 4;
// e
next[5] = next[4];
next[4] = 5;
last = 2;
cur = 5;
// ]
cur = last = 2;
// _
next[7] = next[2];
next[2] = 7;
last = 7;
cur = 7;
for(int i = next[0]; i != 0; i = next[i])
next[0] = 4; next[4] = 5; next[5] = 1; next[1] = 2; next[2] = 7; next[7] = 0;
再回首。
邻接表建图:
tot ++;
next[tot] = first[ff];
first[ff] = tot;
这个就没有什么好说的了。