2013年7月4日 星期四

UVA 11988 Broken Keyboard (a.k.a. Beiju Text)

#include<iostream>
#include<cstdio>
#include<list>
#include<cstring>
using namespace std;
list<int> SJ;
list<int>::iterator iter;
char c[100000];

int main()
{
    while( scanf("%s", &c)!=EOF )
    {
        SJ.clear(); int flag = 0;
        advance(iter,SJ.size());
        int c_size = strlen(c);
        for(int i = 0; i < c_size; i++)
        {
            if( c[i] == ']' ){ flag = 0; }
            else if( c[i] == '[' ){ flag = 1; iter = SJ.begin(); }
            else
            {
                 if(SJ.size()==0||flag==0){ SJ.push_back(i); }
                 else{SJ.insert(iter,i);}
            }
         
        }
     
        for(iter=SJ.begin(); iter!=SJ.end(); ++iter)
            printf("%c", c[*iter]);
        printf("\n");
    }  
}


沒有留言:

張貼留言