Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
不用任何算法 172ms(没用库函数比较)#include<cstdio> #include<cstring> using namespace std; char s[1000001] , tem[1000001]; int n[1000001]; bool solve(char*k , char*p) { int l = strlen(p); for (int i = 0 ; i <= l - 1 ; i++) if(p[i]!=k[i]) return false; return true; } int main() { int len , i , j; bool flag; while(scanf("%s",&s)!=EOF) { len = strlen(s); flag = false; if(len==1&&s[0]=='.') break; for (i = 1 ; i <= len/2 ; i++) { if(len%i!=0) continue; strcpy(tem,s+len-i); for (j = 0 ; j <= len/i - 1 ; j++) if (!solve(s+j*i,tem)) break; if (j==len/i) { flag = true; printf("%d\n",len/i); break; } } if(!flag) printf("1\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator