PersonalCorpus 版 (精华区)

Your C++ program has solved Ok the problem 10100 (Longest Match)
in 0.060 seconds using as much as 1432 kbytes of virtual memory.


void main()
{
    char w1[1000][22],w2[1000][22];
    char s[1005];
    int i,j,k,m,n,t=0,p;
    int c[502][502];

    while (gets(s)!=NULL) {
        printf("%2d. ",++t);
        if (strlen(s)==0) {
            printf("Blank!\n");
            gets(s);
            continue;
        }
        i=0; m=0;
        while (s[i]>0) {
            while (!isalpha(s[i])&&(!isdigit(s[i]))&&(s[i]!=0)) i++;
            if (s[i]==0) break;
            k=0; while (isalpha(s[i])||isdigit(s[i])) { w1[m][k]=s[i]; 
k++; i++; }
            w1[m][k]=0; m++;
        }
        gets(s);
        if (strlen(s)==0) {
            printf("Blank!\n");
            continue;
        }
        i=0; n=0;
        while (s[i]>0) {
            while (!isalpha(s[i])&&!isdigit(s[i])&&(s[i]!=0)) i++;
            if (s[i]==0) break;
            k=0; while (isalpha(s[i])||isdigit(s[i])) { w2[n][k]=s[i]; 
k++; i++; }
            w2[n][k]=0; n++;
        }
        if ((m==0)||(n==0)) {
            printf("Length of longest match: 0\n");
            continue;
        }
        memset(c,0,sizeof(c));
        for (i=1;i<=m;i++) for (j=1;j<=n;j++)
            if (strcmp(w1[i-1],w2[j-1])==0)
            c[i][j]=c[i-1][j-1]+1;
            else if (c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j];
            else c[i][j]=c[i][j-1];
        printf("Length of longest match: %d\n",c[m][n]);
    }
}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:6.263毫秒