uva 11988 Broken Keyboard (a.k.a. Beiju Text) 链表

/* ***********************************************
Author        :xryz
Email         :523689985@qq.com
Created Time  :4-8 11:38:09
File Name     :BrokenKeyboard.cpp
************************************************ */

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

const int maxx=100000+5;

int main()
{
	int last,cur,next[maxx],i;
	char s[maxx],ch;
	while(~scanf("%s",s+1))
	{
		int len=strlen(s+1);
		cur=0;
		last=0;
		next[0]=0;
		for(i=1;i<=len;i++)
		{
			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(i=next[0];i!=0;i=next[i])
		{
			printf("%c",s[i]);
			//printf("%d ",i);
		}
		/*for(i=0;i<len;i++)
		{
			printf("%d ",next[i]);
		}*/
		printf("\n");
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

posted @ 2015-04-08 12:06  xryz  阅读(153)  评论(0编辑  收藏  举报