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 zhoubizhang at 2010-07-14 09:37:35 on Problem 3450
#include<stdio.h>
#include<string.h>
struct
{
    char a[305];
    int len;
}ans;
char tmp[305];
char tot[4001][205];
int next[401];
void getnext()
{
    int k=-1,i=1;
    int len=strlen(tmp);
    next[0]=-1;
    while(i<=len)
    {
        if(k==-1||tmp[i]==tmp[k])
        {
            i++;
            k++;
            next[i]=k;
        }
        else k=next[k];
    }
}
int kmp(char tmp_1[])
{
    int i=0,k=0,len,lenp,flag=0;
    len=strlen(tmp_1);
    lenp=strlen(tmp);
    while(i<len)
    {
        if(k==-1||tmp_1[i]==tmp[k])
        {
            i++;
            k++;
        }
        else k=next[k];
        if(k>=lenp){flag=1;break;}
    }
    return flag;
}
int main()
{
    int n,i,len,j,f,pan,k,tt;
    while(scanf("%d",&n)!=EOF&&n!=0)
    {
        ans.len=0;
        for(i=1;i<=n;i++)
        {
            scanf("%s",tot[i]);
        }
        len=strlen(tot[1]);
        for(i=0;i<len;i++)
        {
            f=0;
            for(j=i;j<len;j++)
            {
                tmp[f]=tot[1][j];
                f++;
                tmp[f]='\0';
                memset(next,0,sizeof(next));
                getnext();
                pan=1;
                for(k=2;k<=n;k++)
                {
                    tt=kmp(tot[k]);
                    if(tt==0){pan=0;break;}
                }
                if(pan==0)break;
                else
                {
                     if(ans.len<f)
                     {
                        ans.len=f;
                        strcpy(ans.a,tmp);
                     }
                     else if(ans.len==f)
                     {
                        if(strcmp(ans.a,tmp)>0)
                        strcpy(ans.a,tmp);
                     }
                }
            }
        }
        if(ans.len==0)printf("IDENTITY LOST\n");
        else printf("%s\n",ans.a);
    }
    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