zoukankan      html  css  js  c++  java
  • UVa11988-破损的键盘 Broken Keyboard

    题目描述

    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

    分析

    终于搞懂了链表的用法...之前还是觉得很难。

    又是证明了这点读程序需要异常强大的耐心...反复的读,写出步骤,画出示意图,意思也就出来了。

    代码

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 const int maxn=100000+5;
     6 int last,cur,next[maxn];
     7 char s[maxn];
     8 int main()
     9 {
    10     while(cin>>s+1)//(scanf("%s",s+1)==1)
    11     {
    12         
    13         int n=strlen(s+1);
    14         /*for(int i=0;i<n;i++)
    15         {
    16             cout<<s[i]<<" ";
    17         }*/
    18         last=cur=0;
    19         next[0]=0;
    20         for(int i=1;i<=n;i++)
    21         {
    22             char ch=s[i];
    23             if(ch=='[')cur=0;
    24             else if(ch==']')cur=last;
    25             else{
    26                 next[i]=next[cur];
    27                 next[cur]=i;
    28                 if(cur==last) last=i;
    29                 cur=i;
    30             }
    31         }
    32         for(int i=next[0];i!=0;i=next[i])
    33         cout<<s[i];
    34         cout<<endl;
    35     }
    36     return 0;
    37  } 
  • 相关阅读:
    springboot(eureka子项目)+idea+jsp 404问题
    什么是区块链以及他的6个特征?
    elasticsearch启动时提示内存不足错误的解决方法
    ElasticSearch 安装root用户启动失败问题解决
    防抖节流(立即执行和延时执行)
    将数字转为千分制格式(最简单)
    微信H5跳转任意小程序
    原生html+css设置项目主题色(超简单)
    H5获取手机型号
    css属性——env()和constant()设置安全区域
  • 原文地址:https://www.cnblogs.com/masking-timeflows/p/6783865.html
Copyright © 2011-2022 走看看