zoukankan      html  css  js  c++  java
  • C

    C - Power Strings

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    #define ll              long long
    #define pii             pair<int, int>
    #define rep(i,a,b)      for(ll  i=a;i<=b;i++)
    #define dec(i,a,b)      for(ll  i=a;i>=b;i--)
    #define forn(i, n)      for(ll i = 0; i < int(n); i++)
    using namespace std;
    int dir[4][2] = { { 1,0 },{ 0,1 } ,{ 0,-1 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979323846;
    const double eps = 1e-6;
    const int mod = 1e7 + 7;
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    inline ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m % n);
    }
    void exgcd(ll A, ll B, ll& x, ll& y)
    {
        if (B) exgcd(B, A % B, y, x), y -= A / B * x; else x = 1, y = 0;
    }
    
    bool prime(int x) {
        if (x < 2) return false;
        for (int i = 2; i * i <= x; ++i) {
            if (x % i == 0) return false;
        }
        return true;
    }
    inline int qpow(int x, ll n) {
        int r = 1;
        while (n > 0) {
            if (n & 1) r = 1ll * r * x % mod;
            n >>= 1; x = 1ll * x * x % mod;
        }
        return r;
    }
    
    const int N = 1e6+5;
    char s[N];
    int pext[N];
    int len;
    void getnxt(char *s,int *next)
    {
        int k=-1;
        int j=0;
        pext[j]=-1;
        while(j<len)
        {
            if(k==-1 || s[j]==s[k])
            {
                k++;
                j++;
                pext[j]=k;
            }
            else
            {
                k=pext[k];
            }
        }
    }
    
    int main()
    {
        while(scanf("%s",s))
        {
            if(strcmp(s,".")==0)
                break;
            int sum=0;
            len=strlen(s);
            getnxt(s,pext);
            int z;
            z=len-pext[len];
            if(len%z==0)
            {
                for(int i=1;i<=len;i++)
                {
                    if(i%z==0)
                        sum++;
                }
                printf("%d
    ",sum);
            }
            else
            {
                printf("1
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    如何在Nginx下配置PHP程序环境
    PHPStorm2016如何安装主题
    Yii2初级入门教程
    递归递归!!
    PHP值传递和引用传递的区别
    网站移植到linux上后常犯的错误
    PHP之function_handling 函数
    PHP如何使用免费在线客服插件
    PHP快速入门 常用配置
    PHP快速入门 如何操作MySQL
  • 原文地址:https://www.cnblogs.com/dealer/p/13356407.html
Copyright © 2011-2022 走看看