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;
    }
    //

  • 相关阅读:
    C# switch-case
    Python学习日记之中文支持
    C++学习笔记(一)之指针
    python CGI 编程实践
    linux 配置 python3 CGI
    PowerShell入门简介
    资源整合,总有你想要的
    python 爬虫之 urllib库
    一天学一个Linux命令:第一天 ls
    DG磁盘分区提示错误
  • 原文地址:https://www.cnblogs.com/Wade-/p/5748588.html
Copyright © 2011-2022 走看看