C语言:判断最长重复字符串

C语言:判断最长重复字符串

#include 
#include 
#include
#include
char *str_out(char * str_);
char *mid(char * ,int ,int);
#define MON1  1
const int MAX = 3;
int main(int argc, char *argv[])
{
	char num[100]="NULL",*p="\0",s[]="ok",p_str[]="abcdefghijklmnopqrstuvwxyz0123456789";
	int tongji=0;
	printf("你好你要判断的最长重复字符串!\r\n");
	scanf("%s",&num);
   printf("最长字符为:%s\n",str_out(num));
	getchar();
	return 0;
}
char *str_out(char * str_){
	char *p=NULL,*temp=NULL,str1[100]="\0",str2[100]="\0",str3[100]="\0";
	int i=0,j=0,k=0,str_Len=0,str_changdu=1,str_chongfu=1; 
   p=str1;temp=str2;
	str_Len=strlen(str_);
    for(i=1;i<str_Len;i++)
	{
		str_changdu=1;
     for(k=1;(k+i)<=str_Len;k++)
		{
			strcpy(p,mid(str_,k,i));
			//printf("%s\n",p);
			str_chongfu=1;
			for(j=k+i;(j+i)<=(str_Len+1);j++)
			{
				strcpy(temp,mid(str_,j,i));
				//printf("===%s\n",temp);
				if(strcmp(p,temp)==0)
				{
				str_chongfu++;
				if(str_chongfu>str_changdu) 
				{str_changdu=str_chongfu;strcpy(str3,p);
					printf("最长字符为:%s,重复%d次\n",str3,str_chongfu);
				}
				}	
			}
		}	
	}
	return str3;
}
char *mid(char * str_,int start,int end){//自己写的MID函数
	int i;char s[50]="\0";
	for (i=0;i<end;i++){
		s[i]=str_[start+i-1];
	}
   //puts(s);
	return s;
}

你可能感兴趣的:(编程)