Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 713 Solved: 231 Description Early computer used line editor, which allowed text to be created and changed only within one line at a time. However, in line editor programs, typing, editing, and document display do not occur simultaneously (unlike the modern text editor like Microsoft Word). Typically, typing does not enter text directly into the document. Instead, users modify the document text by entering simple commands on a text-only terminal.
Here is an example of a simple line editor which can only process English. In addition, it has two commands. ‘@’ and ‘#’. ‘#’ means to cancel the previous letter, and ‘@’ is a command which invalidates all the letters typed before. That is to say, if you want type “aa”, but have mistakenly entered “ab”, then you should enter ‘#a’ or ‘@aa’ to correct it. Note that if there is no letter in the current document, ‘@’ or ‘#’ command will do nothing.
Input The first line contains an integer T, which is the number of test cases. Each test case is 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 be no empty line in the test data.
Sample Input 2 ab#a ab@aa Sample Output aa aa Hint Source 中南大学第四届大学生程序设计竞赛
题目大意: 行编辑器 解题思路: 使用vector进行模拟,要熟悉相关STL的使用
#include<iostream> #include<cstring> #include<stack> #include<vector> #include<queue> #include<string> using namespace std; vector<char> v; string s; int main() { int T; cin>>T; while(T--) { v.clear(); cin>>s; int len=s.length(); for(int i=0;i<len;i++) { if(s[i]=='@') { if(!v.empty()) v.clear(); } else if(s[i]=='#') { if(!v.empty()) v.pop_back(); } else v.push_back(s[i]); } vector<char>::iterator it; for(it=v.begin();it!=v.end();it++) { cout<<*it; } cout<<endl; } return 0; }