WEEK3-2020/9/29
Problem A - Broken Keyboard-UVa 11988
Difficuty: 2 | tag: deque/list
You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problem with
the keyboard is that sometimes the “home” key or the “end” key gets automatically pressed (internally).
You’re not aware of this issue, since you’re focusing on the text and did not even turn on the
monitor! After you finished typing, you can see a text on 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 are several test cases. Each test case is a single line containing at least one and at most 100,000
letters, underscores and two 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 on 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
Analysis
Relatively simple, we can use deque or list to meet the demand.
Using List may be easier, for if we use deque we need reverse the item when insert front, while list needn’t。
MyCode
#include <iostream>
#include <algorithm>
#include <string.h>
#include <list>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
string s;
while(cin >> s)
{
list<char> line;
auto it = line.begin();
for(auto st : s)
{
if(st == '[')
it = line.begin();
else if(st == ']')
it = line.end();
else
{
it = line.insert(it, st);
++it;
}
}
for(auto word : line)
{
cout << word;
}
cout << endl;
}
}
Problem B - Remove Adjacent CodeForces - 1321C
Difficuty: 2 | tag: greedy
刚刚折腾完增加字符的操作,现在就来搞删除吧,给你一个由小写字母组成的字符串s,现在要做删除操作,不过不能随便删,要求是某个字母的两边,存在一个字母序小1的字母的时候,它就可以删除,例如说,“cabcb”ÿ