Harbin Polytechnic Oj--simple Line Editor

Source: Internet
Author: User
Tags line editor

Simple line Editor

Time limit:1000 MS

Memory limit:65536 K

Total submit:573 (151 users)

Total accepted:183 (139 users)

Rating:

Special Judge:no

Description

Early Computer used line editor, which allowed text to is created and changed only within one line at a time. However, in line editor programs, typing, editing, and document display does not occur simultaneously (unlike the modern Tex T editor like Microsoft Word). Typically, typing does not enter text directly into the document. Instead, users modify the document text by entering-commands on a text-only terminal.

Here's an example of a simple line editor which can only process 中文版. In addition, it has both commands. ' @ ' and ' # '. ' # ' means to cancel the previous letter, and ' @ ' was a command which invalidates all the letters typed before. That's to say, if you want Type "AA", but has mistakenly entered "AB", then you should enter ' #a ' or ' @aa ' to correct it . Note that if there are no letter in the current document, ' @ ' or ' # ' command would do nothing.

Input

The first line contains a integer T, which is the number of the test cases. Each test case was a typing sequence of a line editor, which contains only lower case letters, ' @ ' and ' # '.

Output

For each test case, print one line which represents the final document of the user. There would is no empty line in the test data.

Sample Input

2
Ab#a
[Email protected]

Sample Output

Aa
Aa

Think of two ways to do, with the STL to do, a lot of container details, do not understand, these details to understand, do up to a duck.

Vector container to do:

#include <iostream> #include <vector> #include <string>using namespace Std;int main () {string Str;int T ; Cin>>t;while (t--) {cin>>str;vector<char>ls;for (int i=0;i<str.size (); i++) {if (((str[i]== ' # ') || (str[i]== ' @ ')) && (Ls.size () ==0)) Continue;else if (str[i]== ' @ ') ls.clear (); else if (str[i]== ' # ') ls.pop_back (); else {Ls.push_ Back (Str[i]);}} For (Vector<char>::iterator Iter=ls.begin (); Iter!=ls.end (); iter++) cout<<*iter;cout<<endl; Ls.clear ();} return 0;}


Do it with the stacks you just learned!

More smoothly! Be aware that the stack is checked for empty before each pop ().

AC:

#include <iostream> #include <stack> #include <string>using namespace Std;int main () {int t;cin> >t;string Str;while (t--) {stack<char>gq;cin>>str;for (int i=0;i<str.size (); i++) {if (str[i]!= ' # ') &&str[i]!= ' @ ') Gq.push (Str[i]), else if (str[i]== ' # ' &&!gq.empty ()) Gq.pop (); else if (str[i]== ' @ ' & &!gq.empty ()) {while (!gq.empty ()) {Gq.pop ();}}} int Dic=0;char cnt[100000];while (!gq.empty ()) {cnt[dic++]=gq.top (); Gq.pop ();} for (int t=dic-1;t>=0;t--) Cout<<cnt[t];cout<<endl;} return 0;}


Harbin Polytechnic Oj--simple Line Editor

Related Article

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.