Original question:
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 character S ' [' 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
English:
Give you a piece of text where the ' [' Home key goes to the head of the text, '] ' represents the end key, which is the tail of the text.
Now give you a piece of text that asks you to set the ' [' and '] ' according to the prescribed text.
#include <bits/stdc++.h> using namespace std; list<string> ls; string s; int main ()
{Ios::sync_with_stdio (false);
while (cin>>s) {ls.clear ();
int i=0;
string tmp;
while (I!=s.size ()) {int flag=0;
if (s[i]!= ' [') {if (s[i]!= '] ') tmp+=s[i];
i++;
} else {ls.push_back (TMP);
Tmp.clear ();
i++; for (; S[i]!= '] ' &&i!=s.size (); i++) {if (s[i]== ' [') break
;
Tmp+=s[i];
} ls.push_front (TMP);
Tmp.clear ();
}} ls.push_back (TMP);
for (auto It=ls.begin (); It!=ls.end (); it++) cout<<*it;
cout<<endl;
} return 0; }
Answer:
Examples of data structures in purple books, often inserted in the tail and the value can be linked list. The code in the book is a linked list that is modeled with a hash table, and I use the list in STL directly.