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 I08690127 at 2009-07-25 10:29:48 on Problem 1226
#include<stdio.h>
#include<string.h>
#define N 105
int func(char *temp1,char *temp2,char a[][N],int u,int n);
char a[N][N],temp1[N],temp2[N];
int len[N],lx,lmin;
int main(){
    int i,j,k;
    int p,t,n,u,flag;
    scanf("%d",&t);
    while(t--){
        memset(a,0,sizeof(a));
        memset(temp1,0,sizeof(temp1));
        memset(temp2,0,sizeof(temp2));
        scanf("%d",&n);
        for(i=0;i<n;i++){
            scanf("%s",a[i]);
            len[i]=strlen(a[i]);
            }
        for(i=1,lmin=len[0],lx=0;i<n;i++)
            if(len[i]<lmin){
                lmin=len[i];
                lx=i;
                }
        flag=0;
        for(i=lmin;i>=1;i--){
            for(j=0;j+i<=lmin;j++){
                u=0;
                for(k=j;k<j+i;k++)
                    temp1[u++]=a[lx][k];
                u=0;
                for(k=j+i-1;k>=j;k--)
                    temp2[u++]=a[lx][k];
                /*printf("%s %s\n",temp1,temp2);*/
                if(func(temp1,temp2,a,u,n)==1){
                    printf("%d\n",u);
                    flag=1;
                    break;
                    }
                memset(temp1,0,sizeof(temp1));
                memset(temp2,0,sizeof(temp2));
                }
            if(flag==1)
                break;
            }
        if(flag==0)
            printf("%d\n",flag);
        }
    return 0;
    }
int func(char *temp1,char *temp2,char a[][N],int u,int n){
    int p=0,i=0,j;
    for(i=0;i<n;i++){
        for(j=0;j+u<=strlen(a[i]);j++){
            if(!memcmp(temp1,a[i]+j,u)){
                p++;
                break;
                }
            else if(!memcmp(temp2,a[i]+j,u)){
                p++;
                break;
                }
            }
        if(p!=i+1)
            return 0;
        }
    return 1;
    }
//谢谢

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