poj 1035

来源:互联网 发布:国内的人工智能龙头股 编辑:程序博客网 时间:2024/05/01 15:17

暴力水过,79ms

#include <iostream>#include <cstdio>#include <cstring>using namespace std;char tx[10000+10][20];char s[20];int len[10000+10],loc[10000+10];int main(){    int i=0;    while(scanf("%s",tx[i]))    {        if(strcmp(tx[i],"#")==0) break;        len[i]=strlen(tx[i]);        i++;    }    int tot=0,k,p,flag;     while(scanf("%s",s))    {        tot=0;        if(strcmp(s,"#")==0) break;        int j,le=strlen(s);        for(j=0;j<i;j++)        {            flag=0;            if(le==len[j])            {                for(k=0;k<le&&flag<=1;k++)                {                    if(s[k]!=tx[j][k]) flag++;                }                if(flag==0) break;                else if(flag==1) loc[tot++]=j;            }            else if(le==(len[j]+1))            {                flag=0;                for(k=0,p=0;k<len[j]&&flag<=1;)                {                    if(s[p]!=tx[j][k])                    {                        flag++;                        p++;                    }                    else                    {                        p++;                        k++;                    }                }                if(flag<=1) loc[tot++]=j;            }            else if((le+1)==len[j])            {                flag=0;                for(k=0,p=0;p<le&&flag<=1;)                {                    if(s[p]!=tx[j][k])                    {                        flag++;                        k++;                    }                    else                    {                        p++;                        k++;                    }                }                if(flag<=1) loc[tot++]=j;            }        }        if(j<i) printf("%s is correct\n",s);        else        {            printf("%s:",s);            for(k=0;k<tot;k++) printf(" %s",tx[loc[k]]);            printf("\n");        }    }    return 0;}