zoukankan      html  css  js  c++  java
  • 例题6-4 Broken Keyboard UVa11988

    题目分析:

    起初这道题目没有做出来,原因是我一直想把整块区域一并插入,而不是逐个插入。今后做题应该注意这个问题,把问题分解去考虑,也许会少走许多弯路。

    下边附上AC代码

    #include <cstdio>
    #include <cstring>
    #include <cctype>
    char s[100000 + 10];
    int next[100000 + 10];
    int main(){
        while(scanf("%s", s + 1) == 1){
            int len=strlen(s+1);
            int cur = 0,last=0;
            next[0] = 0;
            for(int i = 1;i <= len;i++){
                if(s[i] =='['){
                    cur=0;
                }
                else if(s[i] ==']'){
                    cur=last;
                }
                else {
                    next[i]=next[cur];
                    next[cur]=i;
                    if(cur == last)last = i;
                    cur=i;
                }
            }
            for(int i = next[0];i != 0;i = next[i]){
                printf("%c",s[i]);
            }
            printf(" ");

        }
        return 0;
    }
    //

  • 相关阅读:
    Nim or not Nim? hdu3032 SG值打表找规律
    Maximum 贪心
    The Super Powers
    LCM Cardinality 暴力
    Longge's problem poj2480 欧拉函数,gcd
    GCD hdu2588
    Perfect Pth Powers poj1730
    6656 Watching the Kangaroo
    yield 小用
    wpf DropDownButton 源码
  • 原文地址:https://www.cnblogs.com/Wade-/p/5748588.html
Copyright © 2011-2022 走看看