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

我没用kmp做的,不知道为什么老师run time error,有空的好心牛帮我看看呀

Posted by ljl08 at 2007-08-14 19:48:04 on Problem 2406
#include <stdio.h>
#include <string.h>
int cal(char *str){
	int count[128],min,a,n=1,j,k;
	memset(count,0,sizeof(count));
	int i=0;
	while(str[i]!='\0'){
		count[str[i]]++;
		i++;
	}
	i=0;min=1000100;
	while(i<128){
		if(count[i]!=0&&count[i]<min)min=count[i];
		i++;
	}
	a=strlen(str);
	i=1;
	int m=min;
	while(min&&i++){
		if(a%min!=0){
			while(min%i)i++;
			min=m/i;
			continue;
		}
		bool flag=true;
		for(j=1;j<min;j++){
			for(k=0;k<a/min;k++){
				if(str[k+j*a/min]!=str[k+(j-1)*a/min]){flag=false;break;}
			}
			if(!flag)break;
		}
		if(flag)return min;
		else{
			while(min%i)i++;
			min=m/i;
		}
	}
	return 1;
}
void  main(){
	char str[1000100];
	scanf("%s",&str);
	while(strcmp(str,".")!=0){
		printf("%d\n",cal(str));
		scanf("%s",&str);
	}
}

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