zoukankan      html  css  js  c++  java
  • poj1035 Spell checker

    字符串的基本题,暴力也可以过。

    第一个#之前是字典中的字符串,第二个#之前是要check的字符串。

    逐个讨论,相等的话就直接输出correct。

    字符串长度相同或相差一的就看是否只有一个字符不同。

    #include<string.h>
    #include<stdio.h>
    #include<iostream>
    using namespace std;
    char dic[10001][16],check[51][16];
    int main()
    {
        //freopen("test.txt","r",stdin);
        int flag=0;
        char temp[16];
        int N=0,M=0;
        int i,j;
        while(flag!=2)
        {
            scanf("%s",temp);
            if(temp[0]=='#')
            {
                flag++;
                continue;
            }
            if(flag==0)
            {
                strcpy(dic[N],temp);
                N++;
            }
            else
            {
                strcpy(check[M],temp);
                M++;
            }
        }
        bool correct;
        char obj[10001][16];
        int num,u,v,t;
        for(i=0;i<M;i++)
        {
            correct=false;
            num=0;
            for(j=0;j<N;j++)
            {
                int clen=strlen(check[i]),dlen=strlen(dic[j]);
                if(strcmp(check[i],dic[j])==0)
                {
                    correct=true;
                    break;
                }
                if(clen==dlen)
                {
                    u=0,v=0,t=0;
                    while(u<clen)
                    {
                        if(check[i][u]!=dic[j][v])
                        t++;
                        u++;
                        v++;
                    }
                    if(t>=2)
                    continue;
                    strcpy(obj[num],dic[j]);
                    num++;
                    continue;
                }
                if(clen-dlen==1)
                {
                    u=0,v=0,t=0;
                    while(u<clen&&v<dlen)
                    {
                        if(t==2)
                        break;
                        if(check[i][u]==dic[j][v])
                        {
                            u++;
                            v++;
                        }
                        else
                        {
                            u++;
                            t++;
                        }
                    }
                    if(t!=2)
                    {
                        strcpy(obj[num],dic[j]);
                        num++;
                    }
                }
                if(dlen-clen==1)
                {
                    int u=0,v=0,t=0;
                    while(u<clen&&v<dlen)
                    {
                        if(t==2)
                        break;
                        if(check[i][u]==dic[j][v])
                        {
                            u++;
                            v++;
                        }
                        else
                        {
                            v++;
                            t++;
                        }
                    }
                    if(t!=2)
                    {
                        strcpy(obj[num],dic[j]);
                        num++;
                    }
                }
            }
            if(correct)
            printf("%s is correct\n",check[i]);
            else
            {
                printf("%s:",check[i]);
                for(j=0;j<num;j++)
                printf(" %s",obj[j]);
                printf("\n");
            }
        }
        return 0;
    }
  • 相关阅读:
    WPS项目编号问题
    Allegro转换PADS终极篇(转载)
    Allegro16.3约束设置 (转载)
    转:浮点数在计算机中存储方式
    转:十进制小数转化为二进制小数
    变量的存储类别 内部函数和外部函数
    关于Nios II的启动分析(转载)
    Allegro学习(http://www.asmyword.com/forum.php?mod=forumdisplay&fid=86)
    cf1113 C. Sasha and a Bit of Relax
    D. Jongmah cf1110
  • 原文地址:https://www.cnblogs.com/longlongagocsu/p/2880379.html
Copyright © 2011-2022 走看看