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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Broken Keyboard (a.k.a. Beiju Text)相关的知识,希望对你有一定的参考价值。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<sstream>
using namespace std;
#define N 100005
char a[N];
int nest[N];
char ans[N];
int main()
{
    int i, j, len;
    while (cin >> a)
    {
        int k, cur, last;
        k = cur = last = 0;
        nest[0] = -1;
        for (i = 0; a[i]; i++)
        {
            if (a[i] == [)
                cur = 0;
            else
                if (a[i] == ])
                    cur = last;
                else
                {
                    k++;
                    ans[k] = a[i];
                    nest[k] = nest[cur];
                    nest[cur] = k;
                    cur = k;
                    if (nest[k] == -1) last = k;
                }
        }
        int t = nest[0];
        while (t != -1)
        {
            printf("%c", ans[t]);
            t = nest[t];
        }
        printf("\\n");
    }
    return 0;
}

 

数组模拟链表

技术分享

 

以上是关于Broken Keyboard (a.k.a. Beiju Text)的主要内容,如果未能解决你的问题,请参考以下文章

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

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

D - Broken Keyboard (a.k.a. Beiju Text) (破损的键盘)

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

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

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