UVA - 455 Periodic Strings【字符串】

版权声明:版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/YT201758501112/article/details/83958459

Periodic Strings

 UVA - 455 

题目传送门

题目大意:先输入一个数字n,在输入n行字符串,对每一个字符串输出其最小的周期长度,每两个输出间有一空行。

AC代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
char str[100];
int main()
{
    int n;
    while (scanf("%d",&n)!=EOF)
    {
        while (n--) 
        {
            scanf("%s",str);
            int len=strlen(str); 
            rep(i,1,len) {
                int t=0;
                if (len%i==0)
                {
                    for (t=i;t<len;t++)
                        if (str[t]!=str[t%i])
                            break;
                    if (t==len)
                    {
                        printf("%d\n",i);
                        break;
                    }
                }
            }
            if(n)
                printf("\n");
        }
    }
  return 0;
}

猜你喜欢

转载自blog.csdn.net/YT201758501112/article/details/83958459