Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不用任何算法 172ms(没用库函数比较)

Posted by 1100012760 at 2012-07-03 20:15:35 on Problem 2406
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator