zoukankan      html  css  js  c++  java
  • poj 1035 Spell checker(水题)

    题目:http://poj.org/problem?id=1035

    还是暴搜

      1 #include <iostream>
      2 #include<cstdio>
      3 #include<cstring>
      4 #include<cstdlib>
      5 #include<stack>
      6 #include<queue>
      7 #include<iomanip>
      8 #include<cmath>
      9 #include<map>
     10 #include<vector>
     11 #include<algorithm>
     12 using namespace std;
     13 
     14 char s[50000][100],str[300],a[50000][100];
     15 int main()
     16 {
     17     int i,j,f,n,x,k,cnt,y;
     18     for(i=0; ; i++)
     19     {
     20         scanf("%s",s[i]);
     21         if(strcmp(s[i],"#")==0)
     22             break;
     23     }
     24     n=i;
     25     while(1)
     26     {
     27         f=0;
     28         cnt=0;
     29         y=0;
     30         scanf("%s",str);
     31         if(strcmp(str,"#")==0)
     32             break;
     33         for(i=0; i<n; i++)
     34         {
     35             if(strcmp(s[i],str)==0)
     36             {
     37                 printf("%s is correct
    ",str);
     38                 y=1;
     39                 break;
     40             }
     41         }
     42         if(y==0)
     43         {
     44             for(j=0; j<n; j++)
     45             {
     46                 if((strlen(s[j])-strlen(str))==1)
     47                 {
     48                     x=0;
     49                     for(i=0,k=0; i<strlen(s[j]),k<strlen(str); k++,i++)
     50                     {
     51                        while(s[j][i]!=str[k]&&(k<strlen(str))&&(i<strlen(s[j])))
     52                        {
     53                            if(x==0)
     54                            i++;
     55                            if(x!=0)
     56                            k++;
     57                            x++;
     58                        }
     59                     }
     60                     if(x<=1)
     61                     {
     62                         f=1;
     63                         strcpy(a[cnt++],s[j]);
     64                     }
     65                 }
     66                 if((strlen(s[j])-strlen(str))==-1)
     67                 {
     68                    x=0;
     69                    for(i=0,k=0; i<strlen(s[j]),k<strlen(str); k++,i++)
     70                    {
     71                         while(s[j][i]!=str[k]&&(k<strlen(str))&&(i<strlen(s[j])))
     72                        {
     73                            if(x==0)
     74                            k++;
     75                            if(x!=0)
     76                            i++;
     77                            x++;
     78                        }
     79                    }
     80                    if(x<=1)
     81                     {
     82                         f=1;
     83                         strcpy(a[cnt++],s[j]);
     84                     }
     85                 }
     86                 if((strlen(s[j])-strlen(str))==0)
     87                 {
     88                    x=0;
     89                    for(i=0,k=0; i<strlen(s[j]),k<strlen(str); k++,i++)
     90                    {
     91                        if(s[j][i]!=str[k])
     92                        {
     93                            x++;
     94                        }
     95                    }
     96                    if(x==1)
     97                    {
     98                        f=1;
     99                        strcpy(a[cnt++],s[j]);
    100                    }
    101                 }
    102             }
    103             printf("%s:",str);
    104             if(f)
    105                 for(i=0; i<cnt; i++)
    106                 {
    107                     printf(" ");
    108                     printf("%s",a[i]);
    109                 }
    110 
    111            printf("
    ");
    112         }
    113     }
    114     return 0;
    115 }
  • 相关阅读:
    第十二章 基本数据类型
    第十一章 变量名的力量
    第十章 使用变量的一般事项
    第九章 伪代码编程过程
    第八章 防御式编程
    JMeter简介
    第七章 高质量的子程序
    第六章 可以工作的类
    第五章 软件构建中的设计
    第四章 关键的“构建”决策
  • 原文地址:https://www.cnblogs.com/bfshm/p/3268536.html
Copyright © 2011-2022 走看看