joj1873
2011-09-16 22:28
274 查看
1873:
Power Strings
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
10s | 8192K | 640 | 254 | Standard |
by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).
Each test case is a line of input representing s, a string of printable characters. For each s you should print the largest n such that s = a^n for some string a. The length of s will be at least 1 and
will not exceed 1 million characters. A line containing a period follows the last test case.
Sample Input
abcd aaaa ababab .
Output for Sample Input
1 4 3
这不是一道难题,只要找到字符串循环的最小单位就行了
#include<stdio.h>
#include<string.h>
char str[1000005];
int len;
bool exam(int u,int v)
{
int add=v-u;
// printf("%d %d %d\n",u,v,add);
if(len%add!=0)
return false;
for(int i=u;i<v;i++)
{
int t=i+add;
// printf("%d %d\n",u,v);
while(t<len)
{
if(str[i]!=str[t])
return false;
t=t+add;
// printf("%d %d\n",u,v);
}
}
return true;
}
int find()
{
for(int j=1;str[j]!='\0';j++)
{
if(str[0]==str[j])
{
if(exam(0,j))
return j;
}
}
return len;
}
int main()
{
//freopen("in.txt","r",stdin);
while(gets(str))
{
if(str[0]=='.')
break;
len=strlen(str);
int m=find();
printf("%d\n",len/m);
}
return 0;
}
相关文章推荐
- joj 1873 Power Strings
- JOJ 1003 Channel Allocation
- JOJ 1115 1116 1117 1118
- joj 登不上了……,题写完rt,
- joj 1026: The Staircases
- joj 1020 格式输出
- joj2697
- joj 2699: 16 and 18 博弈 最后一个取石子者输
- joj 2443
- joj 2223: A Bug's Life (ws版的并查集)
- joj 2062 Sum II (搜索是否存在指定和的组合)
- joj 1066
- joj1198
- joj 1131 Intersection
- joj2252
- joj2529
- joj 1171
- joj 2660 河床
- joj 1195
- joj1474 Soundex Indexing