Broken Keyboard (a.k.a. Beiju Text) UVA, 11988(链表)

Broken Keyboard (a.k.a. Beiju Text)

From:UVA,
11988

Time Limit: 1000 MS


Broken Keyboard (a.k.a. Beiju Text)

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). The size of input file does not exceed 5MB.

Output

For each case, print the Beiju text on the screen.

Sample Input

This_is_a_[Beiju]_text
[[]][][]Happy_Birthday_to_Tsinghua_University

Output for the Sample Input

BeijuThis_is_a__text
Happy_Birthday_to_Tsinghua_University

题目大意:某位程序员在用坏掉的键盘打字,这个键盘的home键和end键会是不是自己打印。然后现在给出这样的一串文字,要求你打印出之后会在屏幕上显示的字符串,也就是每次碰到这个健后光标就会移动到这行的最前面和最后面。

解题思路:home键是跳到这一行的开头开始打印,end键是跳到这一行的末尾开始打印。用一个链表将home和end之后的字符串串起来,之后在按顺序输出就可以了。碰到【,则链表的位置到达了最前面,碰到】。链表的位置到最后面,其他时候,正常出入在IT位置处即可。

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<list>
using namespace std;

string str0;
list <char> l;//定义一个char型的list.
list <char>::iterator it=l.begin();//初始化为链表的起点位置,不然it无指向地址,导致程序崩溃。

void solve(){
    for(int i=0;i<str0.length();i++){
        if(str0[i]=='[') it=l.begin();
        else if(str0[i]==']') it=l.end();
        else l.insert(it,str0[i]);
    }
}

void outResult(){
    for(it=l.begin();it!=l.end();it++){
        printf("%c",*it);
    }
    printf("\n");
    l.clear();
}

int main(){
    while(cin>>str0){
        solve();
        outResult();
    }
    return 0;
}
时间: 2024-10-12 19:25:39

Broken Keyboard (a.k.a. Beiju Text) UVA, 11988(链表)的相关文章

Broken Keyboard (a.k.a. Beiju Text) UVA - 11988 (链表)

题目链接:https://vjudge.net/problem/UVA-11988 题目大意:输入一个字符串,输出在原本应该是怎么样的?  具体方法是 碰到' [ ' 回到最前面  碰到' ]'  回到最后面. 思路:很容易可以想到用数组来写,但是仔细分析一下, 原文地址:https://www.cnblogs.com/caijiaming/p/10344484.html

B - Broken Keyboard (a.k.a. Beiju Text) 数组模拟链表

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 iss

UVa 11988 - Broken Keyboard (a.k.a. Beiju Text) 题解

刘汝佳的题目,悲剧文本 -_-||| 这里使用vector<string>容器倒置记录数据,然后从后面输出就可以了. 难度就是不知道这样的文档到底哪里是开始输出,故此使用动态管理内存的容器比较好做. 增加了io处理的O(n)算法也没有上榜,郁闷. #include <stdio.h> #include <vector> #include <string> using std::vector; using std::string; const int MAX_

uva - Broken Keyboard (a.k.a. Beiju Text)(链表)

11988 - Broken Keyboard (a.k.a. Beiju Text) You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problemwith the keyboard is that sometimes the “home” key or the “end” key gets automatically pressed(internally).Yo

UVA11988 Broken Keyboard (a.k.a. Beiju Text)【数组模拟链表】

Broken Keyboard (a.k.a. Beiju Text) 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 (inter

N - Broken Keyboard (a.k.a. Beiju Text)

N - Broken Keyboard (a.k.a. Beiju Text) Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description 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 som

11988 - Broken Keyboard (a.k.a. Beiju Text)

Broken Keyboard (a.k.a. Beiju Text) 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 (inter

Uva11988 Broken Keyboard (a.k.a. Beiju Text)(就是先输出括号的字符)

Description Problem B Broken Keyboard (a.k.a. Beiju Text) 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 automa

UVA11988 Broken Keyboard (a.k.a. Beiju Text)

看到大一练习题,睡前水一水~~~ Problem B Broken Keyboard (a.k.a. Beiju Text) 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 a