zoukankan      html  css  js  c++  java
  • UVa 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 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

    Sample Output

    BeijuThis_is_a__text
    Happy_Birthday_to_Tsinghua_University

    题意

    每次把“[”和"]"里面的东西放到最前面

    题解

    正常暴力不用考虑,TLE

    数组操作的就不说了,这是用链表做的

    代码

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 struct node
     4 {
     5     char data;
     6     struct node *next;
     7 };
     8 int main()
     9 {
    10     char s[100005];
    11     while(scanf("%s",s)!=EOF)
    12     {
    13         node *head=(node*)malloc(sizeof(node)),*rear,*p;
    14         head->next=NULL;
    15         p=rear=head;//第一个对头操作
    16         for(int i=0;s[i];i++)
    17         {
    18             char ch=s[i];
    19             if(ch=='[')
    20                 p=head;
    21             else if(ch==']')
    22                 p=rear;
    23             else
    24             {
    25                 node *q=(node*)malloc(sizeof(node));
    26                 q->data=ch;
    27                 q->next=p->next;
    28                 p->next=q;
    29                 if(p==rear)
    30                     rear=q;
    31                 p=q;
    32             }
    33         }
    34         p=head->next;
    35         while(p)
    36         {
    37             printf("%c",p->data);
    38             p=p->next;
    39         }
    40         printf("
    ");
    41     }
    42     return 0;
    43 }
  • 相关阅读:
    安卓给DatePicker设置选择日期后的监听
    Linux端口相关一些命令
    安卓使用Zxing创建二维码
    vue中this.$router.push()路由跳转和传参
    C# 获取请求头中包含指定元素的值
    各种JSON格式数据
    SQL 中 char、nchar、varchar、nvarchar 的区别
    vue中表单修饰符
    vue 中的export 、 export default 和 new Vue({})
    String or binary data would be truncated.
  • 原文地址:https://www.cnblogs.com/taozi1115402474/p/8457720.html
Copyright © 2011-2022 走看看