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 }
  • 相关阅读:
    《C语言课程设计与游戏开发实践课程》67章总结
    祖玛(Zuma)
    .net 实现微信公众平台的主动推送信息
    关于ASP与C#的感悟
    不同方面高手的地址。
    ASP中关于全局页面的作用 asax文件
    学习C#,开始了我的第一个进程。
    江苏立方网络科技有限公司招聘PHP工程师
    网上看到的ArcEngine控制地图显示范围的好方法(记下)
    3DS文件结构
  • 原文地址:https://www.cnblogs.com/taozi1115402474/p/8457720.html
Copyright © 2011-2022 走看看