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

超时代码求帮改

Posted by LXY5201314 at 2018-01-24 22:42:20 on Problem 2406
#include<stdio.h>
#include<string.h>
int count1,k;
int compare(char str1[1000004],char str[1000004])
{
    int k1,i,j,a=1;
    k1=strlen(str1);
    for(i=k1;i<k;)
    {
        j=0;
        while(j<k1&&str1[j]==str[i++])j++;
        if(j!=k1)return 0;
        else a++;
    }
    if(i==k)return a;
    else return 0;
}
int main(void)
{
    char str[1000004],str1[1000004];
    int i,sum;
    while(scanf("%s",str)!=EOF)
    {
        if(strcmp(str,".")==0)break;
        sum=0;
        k=strlen(str);
        for(i=0;i<k;i++)
        {
            str1[i]=str[i];str1[i+1]='\0';
            count1=compare(str1,str);
            if(sum<count1){sum=count1;break;}
        }
        printf("%d\n",sum);
    }
    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