• POJ_1961 KMP next的典型应用 类似于 poj2406


    POJ_1961 KMP next的典型应用 类似于 poj2406
    /* 
     * POJ_1961 KMP next的典型应用 类似于 poj2406
     * Author : a_clay  2014/05/06 
     */  
    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define Bug cout << "here
    ";
    
    using namespace std;
    const int M = 1000005;
    
    char t[M];
    int next[M];
    
    void get_next(int len) {
        int i, j;
        i = 0, j = -1;
        next[0] = -1;
        while (i < len) {
            if (j == -1 || t[i] == t[j]) {
                i++, j++, next[i] = j;
            }
            else {
                j = next[j];
            }
        }
    }
    int main() {
        int n, ca = 1;
        while (scanf("%d", &n) && n != 0) {
            scanf("%s", t);
            get_next(n);
            printf("Test case #%d
    ", ca++);
            for (int i = 2; i <= n; i++) {
                if (i% (i - next[i]) == 0 && i / (i - next[i]) > 1) {
                    printf("%d %d
    ", i, i / (i - next[i]));
                }
            }
            printf("
    ");
        }
        return 0;
    }
    

  • 相关阅读:
    类属性、实例属性
    多态
    重载
    多继承
    继承介绍以及单继承
    析构
    构造
    self
    方法
    属性
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786776.html
Copyright © 2020-2023  润新知