UVA11988 - Broken Keyboard (a.k.a. Beiju Text)

来源:互联网 发布:跑酷教程软件 编辑:程序博客网 时间:2024/06/08 06:03

这个题就是一个字符串用来存s,一个int数组 用来村下标,然后不停的插入下标即可。

#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn=100000+10;int cnt,last,next[maxn];char s[maxn];int main(){    ios::sync_with_stdio(false);    while(scanf("%s",s+1)!=EOF){        cnt=0,last=0;        int n=strlen(s+1);        next[0]=0;        for(int i = 1;i<=n; i++){            if(*(s+i)=='[') cnt=0;            else if(*(s+i)==']') cnt=last;            else{                next[i]=next[cnt];                next[cnt]=i;                cnt=i;                if(next[i]==0) last=i;//例题源代码找到规律,代码提高了运行效率 原创 效率稍微低一点            }        }        for(int i =next[0]; i; i=next[i]){            cout<<s[i];        }        cout<<endl;    }}


0 0