10887 - Concatenation of Languages

来源:互联网 发布:samba访问windows共享 编辑:程序博客网 时间:2024/06/05 14:31
描述:居然要gets才可以,scanf读入居然过不了,唉……#include <cstdio>#include <cstring>#include  <cstdlib>#define N 1000003#define M 2250010int  n , row , col,flag,m=0,sum;char s_row[1510][12],s_col[1510][12];char s[M][22];int head[N],next[N];int hash(char *p){    int c=strlen(p);    int count=0;    for(int i=0; i<c; i++)        count=(count*26+p[i]-'a')%N;    return count;}int main(){    //freopen("a.txt","r",stdin);    scanf("%d",&n);    while(m<n)    {        sum=0;        scanf("%d%d",&row,&col);        getchar();        for(int i=0; i<row; i++) gets(s_row[i]);        for(int i=0; i<col; i++) gets(s_col[i]);        memset(head,-1,sizeof(head));        memset(next,-1,sizeof(next));        for(int i=0; i<row; i++)            for(int j=0; j<col; j++)            {                strcpy(s[sum],s_row[i]);                strcat(s[sum],s_col[j]);                int count = hash(s[sum]);                int c=head[count];                flag=0;                while(c!=-1)                {                    if(strcmp(s[sum],s[c])==0)                    {                        flag=1;                        break;                    }                    c=next[c];                }                if(!flag)                {                    next[sum]=head[count];                    head[count]=sum++;                }            }        printf("Case %d: %d\n",m+1,sum);        m++;    }    return 0;}

原创粉丝点击