UVA 11988 STL deque (双端队列||链表模拟)
2015-12-22 21:01
417 查看
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
题意:一个不规则的文本‘[’表示home键,‘]’表示end键,这里解释一下按下home键是将光标移动到字符首位,end光标放在末尾。(大家可以试验一下,我今天才知道这两个键的用法)。求正确的文本
题解:直接模拟就可以了,链表最好,时间复杂度低,不过我想一下可以用双端队列模拟
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
题意:一个不规则的文本‘[’表示home键,‘]’表示end键,这里解释一下按下home键是将光标移动到字符首位,end光标放在末尾。(大家可以试验一下,我今天才知道这两个键的用法)。求正确的文本
题解:直接模拟就可以了,链表最好,时间复杂度低,不过我想一下可以用双端队列模拟
#include<iostream> #include<cstdio> #include<map> #include<algorithm> #include<string> #include<cmath> #include<vector> #include<queue> #include<deque> #include<cstring> #include<set> #include<vector> using namespace std; #define LL long long string s; string temp; deque<string>dq; int main() { #ifdef CDZSC freopen("i.txt","r",stdin); #endif while(cin>>s) { char op=0; temp.clear(); for(int i=0;i<s.size();i++) { if(s[i]=='['||s[i]==']') { if(op=='[') { dq.push_front(temp); } else { dq.push_back(temp); } temp.clear(); op=s[i]; } else temp+=s[i]; if(i==s.size()-1) { if(op=='[') { dq.push_front(temp); } else { dq.push_back(temp); } temp.clear(); } } while(!dq.empty()) { printf("%s",dq.front().c_str()); dq.pop_front(); } puts(""); } return 0; }
相关文章推荐
- jqeryUI 文本框自动补全
- JavaEE request.getAttribute request.getParameter
- grub rescue
- Arduino - 多线程库SCoop应用 之 时钟(计时器)
- Auto Layout Guide----(二)-----Auto Layout Without Constraints
- HDU 3450 Counting Sequences(DP + 树状数组)
- UIDatePicker的用法:最小日期和最大日期
- uImage与zImage的区别
- String和CharSequence
- POJ2785 4 Values whose Sum is 0
- duilib底层机制剖析:窗口类与窗口句柄的关联
- 设置UIButton的文字显示位置、字体的大小、字体的颜色
- 如何优化UITableView性能—draw方式
- 使用easyui实现的添加公告功能(后台管理)
- This Android SDK requires Android Developer Toolkit version 23.0.0 or above
- hdu 1806 Frequent values 线段树
- [Android UI界面]RelativeLayou布局
- Builder模式
- (转)Android属性设置android:noHistory="true"
- UITableView的关键内容