【例题 6-4 UVA

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

会链表的插入操作的话。这个就不难了。 放置两个哨兵节点。 然后模拟插入一个节点的过程就好。 实时修改光标就好->即下一个插入的位置。

【代码】

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5;
const int fir = 0, last = N + 10;

int nex[N + 100],len,be;
char s[N + 100];

int main()
{
	//freopen("F:\rush.txt", "r", stdin);
	while (~scanf("%s", s + 1))
	{
		nex[fir] = last;
		int cur = 0;
		be = 0;
		len = strlen(s + 1);
		for (int i = 1; i <= len; i++)
			if (s[i] == '[')
				cur = 0;
			else 
				if (s[i] == ']') cur = be;
				else
				{
					if (nex[cur] == last) be = i;
					nex[i] = nex[cur];
					nex[cur] = i;
					cur = i;
				}
		for (int i = nex[fir]; i != last; i = nex[i]) putchar(s[i]);
		puts("");
	}
	return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7693582.html