UVA 11988 Broken Keyboard (a.k.a. Beiju Text) 字符串处理
2016-08-16 13:34
281 查看
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
根据题意处理就好了
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
根据题意处理就好了
#include<stdio.h> #include<string> #include<cstring> #include<queue> #include<algorithm> #include<functional> #include<vector> #include<iomanip> #include<math.h> #include<iostream> #include<sstream> #include<stack> #include<set> #include<bitset> using namespace std; const int MAX=100005; string Str; bool used[MAX]; struct node { string S; int num; node(string temp,int n):S(temp),num(n) {}; }; bool cmp(node a,node b) { return a.num<b.num; } int main() { cin.sync_with_stdio(false); while (cin>>Str) { memset(used,0,sizeof(used)); int len=Str.length(); int pos=0; vector<node> vec; for (int i=0; i<len; i++) { if (Str[i]==']') { used[i]=true; continue; } if (Str[i]=='[') { int temp=i+1,j=1; used[i]=true; for (i=i+1,j=1; i<len; i++,j++) { used[i]=true; if (Str[i]==']') { vec.push_back(node(Str.substr(temp,j-1),--pos)); break; } if (Str[i]=='[') { vec.push_back(node(Str.substr(temp,j-1),--pos)); i--; break; } if (i==len-1) { vec.push_back(node(Str.substr(temp,j),--pos)); break; } } } } sort(vec.begin(),vec.end(),cmp); for (int i=0; i<(int)vec.size(); i++) { cout<<vec[i].S; } for (int i=0; i<len; i++) { if (!used[i]&&Str[i]!='['&&Str[i]!=']') cout<<Str[i]; } cout<<endl; } return 0; }
相关文章推荐
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)
- 例题6-4 UVA 11988 Broken Keyboard (a.k.a. Beiju Text) 破损的键盘
- UVa 11988 - Broken Keyboard (a.k.a. Beiju Text) 题解
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)
- UVA11988 Broken Keyboard (a.k.a. Beiju Text)【数组模拟链表】
- UVa 11988 - Broken Keyboard (a.k.a. Beiju Text)【链表初接触】
- UVA-11988 Broken Keyboard (a.k.a. Beiju Text) (链表 或 递归)
- [UVA]11988 - Broken Keyboard (a.k.a. Beiju Text) 题解 及一点点感想
- UVa 11988 - Broken Keyboard (a.k.a. Beiju Text) 题解
- UVa 11988 - Broken Keyboard (a.k.a. Beiju Text) 题解
- uva 11988 Broken Keyboard (a.k.a. Beiju Text) 链表
- UVa 11988 Broken Keyboard (a.k.a. Beiju Text) (模拟链表)
- UVa 11988 - Broken Keyboard (a.k.a. Beiju Text) (简单链表)
- UVa 11988 Broken Keyboard (a.k.a. Beiju Text) 数组模拟
- UVa 11988 - Broken Keyboard (a.k.a. Beiju Text)【数组实现链表】
- uva 11988 - Broken Keyboard (a.k.a. Beiju Text)----链表快速插入
- uva 11988 Broken Keyboard (a.k.a. Beiju Text) 链表
- Broken Keyboard(a.k.a.Beiju Text),UVa 11988
- 暑假集训单切赛第二场 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(字符串处理)
- UVA 11988 - Broken Keyboard (a.k.a. Beiju Text)