B-broken Keyboard (a.k.a. Beiju Text) array analog linked list

Source: Internet
Author: User
Tags acos cmath

You ' re typing a long text with a broken keyboard. Well it's not so badly broken. The only problem with the keyboard are that sometimes the "home" key or the "end" key gets automatically pressed (internall Y).
You ' re not aware of this issue, since your ' re focusing on the text and do not even turn on the monitor! After your finished typing, you can see a text in the screen (if you turn on the monitor).
In Chinese, we can call it beiju. Your task is to find the Beiju text.

Input

There is several test cases. Each test case was a single line containing at least one and at the most 100,000
Letters, underscores and special characters ' [' and '] '. ' [' means the ' Home ' key is pressed
Internally, and '] ' means the ' End ' key is pressed internally. The input is terminated by end-of-file
(EOF).

Output

For each case, print the Beiju text in the screen.

Sample Input

This_is_a_[beiju]_text
[[]][][]happy_birthday_to_tsinghua_university

Sample Output

Beijuthis_is_a__text
Happy_birthday_to_tsinghua_university

Broken keyboard, before the C language work, then did not, and then began to want to use a vector, but this insertion does not, will T, and then use the list to write a bit. Vomiting blood, do not know why also T;

List code that will T

#include <iostream> #include <stdio.h> #include <stdlib.h> #include <iomanip> #include < cmath> #include <float.h> #include <string.h> #include <algorithm> #define SF scanf#define PF printf #define PB push_back#define mm (x,b) memset ((x), (b), sizeof (x)) #include <vector> #include <queue>//# Include<map> #define REP (I,a,n) for (int. i=a;i<n;i++) #define PER (i,a,n) for (int i=a;i>=n;i--) typedef long Long Ll;typedef long double ld;typedef double db;const ll Mod=1e9+100;const db e=exp (1); using namespace Std;const double p    I=acos ( -1.0); Char a[100005];struct node{char c; node *next;};    int main () {int x;        while (~SF ("%s", &a)) {node *head,*now,*last,*p;        Head=new node;        int temp=0;        Last=now=head;        Head->next =null;                Rep (I,0,strlen (a)) {if (a[i]== ' [') {now=head;            Temp=1;       } else if (a[i]== '] ') {         Now=last;            Temp=0;                } else {p=new node;                P->c =a[i];                P->next=now->next;                Now->next =p;                Now=p;                if (temp==0) Last=now;            while (Last->next!=null) last=last->next;        }} Last->next =null;        p=head->next;            while (P!=null) {pf ("%c", p->c);            Now=p;            p=p->next;        Free (now);    } pf ("\ n");    } return 0; }
Later see Rujia book on this topic, and then follow this way over the p143, using an array to simulate the list, because it is from left to right, so you can only use a next array to store the characters on the right followed by the following table is good;

AC's

#include <iostream> #include <stdio.h> #include <stdlib.h> #include <iomanip> #include < cmath> #include <float.h> #include <string.h> #include <algorithm> #define SF scanf#define PF printf #define PB push_back#define mm (x,b) memset ((x), (b), sizeof (x)) #include <vector> #include <queue>//# Include<map> #define REP (I,a,n) for (int. i=a;i<n;i++) #define PER (i,a,n) for (int i=a;i>=n;i--) typedef long Long Ll;typedef long double ld;typedef double db;const ll Mod=1e9+100;const db e=exp (1); using namespace Std;const double p    I=acos ( -1.0); Char s[100005];int next[100005],last,cur;int main () {int n,last,cur;        while (SF ("%s", s+1)!=eof) {N=strlen (s+1);        last=cur=0;        next[0]=0;            for (int i=1;i<=n;i++) {if (s[i]== ' [') cur=0;            else if (s[i]== '] ') cur=last;                else {next[i]=next[cur];                Next[cur]=i; if (Cur==laST) last=i;            Cur=i;        }} for (int i=next[0];i!=0;i=next[i]) pf ("%c", S[i]);    PF ("\ n"); } return 0;}

B-broken Keyboard (a.k.a. Beiju Text) Array simulation list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.