紫书UVA11988

数组模拟链表
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn =1000000+5;
int last,cur,nex[maxn];
char s[maxn];
int main()
{
    while(cin>>s+1)
    {
        int n=strlen(s+1);
        last=cur=0;
        nex[0]=0;
        for(int i=1;i<=n;i++)
        {
            if(s[i]=='[')
                cur=0;
            else if(s[i]==']')
                cur=last;
            else
            {
                nex[i]=nex[cur];
                nex[cur]=i;
                if(last==cur) last=i;
                cur=i;
            }
        }
        for(int i=nex[0];i!=0;i=nex[i])
        {
            cout<<s[i];
        }
        cout<<endl;
    }
    return 0;
}

posted @ 2018-04-17 13:11  MCQ  阅读(60)  评论(0编辑  收藏  举报