zoukankan      html  css  js  c++  java
  • poj 1035

    暴力水过,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;
    }
    


  • 相关阅读:
    Python 冒泡排序
    编程规范之注释篇
    编程规范之变量命名篇
    安装Django
    字典&列表的拓展理解
    小球落地
    Python结合sql登陆案例
    面向对象:两手交换牌
    每日一题(一)
    Web应用之LAMP源码环境部署
  • 原文地址:https://www.cnblogs.com/lj030/p/3065562.html
Copyright © 2011-2022 走看看