zoukankan      html  css  js  c++  java
  • POJ 2406 Power Strings

     1 #include <iostream>
     2 #include <cstring>
     3 #include <string>
     4 #include <algorithm>
     5 #include <cstdio>
     6 #define MAXSIZE 1000100
     7 using namespace std;
     8 
     9 char a[MAXSIZE];
    10 int Next[MAXSIZE];
    11 int Len;
    12 
    13 int GetNext()
    14 {
    15     int i = 0, j = Next[0] = -1;
    16     while (i < Len)
    17     {
    18         if (j == -1 || a[i] == a[j])
    19             Next[++i] = ++j;
    20         else
    21             j = Next[j];
    22     }
    23 }
    24 
    25 int main(void)
    26 {
    27     ios::sync_with_stdio(false);
    28     while (true)
    29     {
    30         cin >> a;
    31         if (a[0] == '.')
    32             return 0;
    33         Len = strlen(a);
    34         GetNext();
    35         int period = Len - Next[Len];
    36         if (Len % period == 0)
    37             cout << Len / period << endl;
    38         else
    39             cout << 1 << endl;
    40     }
    41 
    42     return 0;
    43 }
  • 相关阅读:
    UVa10779
    UVa10779
    C++ 内存管理学习笔记
    c++ 学习笔记
    AcWing 275 传纸条
    I
    Tree HDU6228
    Lpl and Energy-saving Lamps
    C
    Secret Poems
  • 原文地址:https://www.cnblogs.com/ducklu/p/8962012.html
Copyright © 2011-2022 走看看