UVA 455(p57)----Periodic Strings

来源:互联网 发布:三级域名申请 编辑:程序博客网 时间:2024/05/29 16:18
#include<cstdio>#include<iostream>#include<cstring>using namespace std;char st[200];int t,flag,f;int main(){    /*freopen("in.in","r",stdin);    freopen("out.out","w",stdout);*/    scanf("%d",&t);    for(int i=1; i<=t; i++)    {        cin>>st;        f=0;        int l=strlen(st);        if(i!=1) puts("");        for(int i=1; i<=l; i++)        {            int flag=1;            if(l%i) continue;            for(int j=i; j<l; j++)                if(st[j]!=st[j%i])                {                    flag=0;                    break;                }            if(flag)            {                printf("%d\n",i);                break;            }        }    }    return 0;}
题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=396
0 0
原创粉丝点击