zoukankan      html  css  js  c++  java
  • uva11988

     虽然简洁度跟佳爷完全没法比,至少accepted很开心了

    #include <iostream>
    #include <string>
    using namespace std;
    const int maxd = 100003;
    char text[maxd];
    int mynext[maxd];
    void init(int len)
    {
     for (int i = 0;i < len;i++)
      mynext[i] = i+1;
     mynext[len] = -1;
    }
    int main(void)
    {
     //read
     string str;
     while (cin >> str)
     {
      //init next[]
      int len=0;
      while (str[len] == '['||str[len] == ']'&&str[len] == '')len++;
      str = str.substr(len);
      len = str.length();
      init(len);
      //core
      int old_tail=0;//承接下文,初始化0处理[]happy类似情况
      for (int i = 0;i < len;i++)
      {
       if (str[i] != '['&&str[i] != ']')old_tail = i + 1;
       else if (str[i] == '[' && (str[i + 1] != '[' && str[i+1] != ']'&& str[i+1]!=''))
       {
        mynext[old_tail] = -1;
        int old_head = mynext[0];
        mynext[0] = i + 1 + 1;//str[i+1]为第一个输出字符
        int j;
        for (j = i + 2;str[j] != '['&&str[j] != ']'&&str[j] != '';j++);
        mynext[j] = old_head;//str[old_head-1]输出的前一个字符为str[j-1]
        i = j-1;//跳过插进前面的字符
       }
       else if(str[i]==']' && (str[i + 1] != '[' && str[i + 1] != ']' && str[i + 1] != ''))
       {
        mynext[old_tail] = i + 1 + 1;
       }
      }
      mynext[old_tail] = -1;
      //output
      for (int i = mynext[0];i != -1;i=mynext[i])
       putchar(str[i-1]);
      putchar(' ');
     }
     
     return 0;
    }

  • 相关阅读:
    CSS
    网络通信
    模块与包
    python异常处理
    python基础考试一整理
    面向对象最后进阶
    面向对象-反射和__getattr__系列
    property、staticmethod和classmethod
    多态和封装
    scala构造器实战
  • 原文地址:https://www.cnblogs.com/schsb/p/7823610.html
Copyright © 2011-2022 走看看