POJ 1035 Spell checker(字符串)

题目链接

考虑各种情况,然后注意敲的稳一点,忘考虑一种情况,2Y.

  1 #include <iostream>

  2 #include <cstdio>

  3 #include <cstring>

  4 #include <queue>

  5 #include <string>

  6 #include <map>

  7 using namespace std;

  8 char word[10001][21];

  9 char s[21];

 10 int len[10001];

 11 int Abs(int x)

 12 {

 13     if(x < 0)

 14     return -x;

 15     else

 16     return x;

 17 }

 18 int main()

 19 {

 20     int i,j,n,k1,k,L,z;

 21     map<string,int>mp;

 22     for(i = 1;;i ++)

 23     {

 24         scanf("%s",word[i]);

 25         len[i] = strlen(word[i]);

 26         if(word[i][0] == '#')

 27         break;

 28         mp[word[i]] = 1;

 29     }

 30     n = i-1;

 31     for(i = 1;;i ++)

 32     {

 33         scanf("%s",s);

 34         if(s[0] == '#') break;

 35         L = strlen(s);

 36         if(mp[s])

 37         {

 38             printf("%s is correct\n",s);

 39             continue;

 40         }

 41         printf("%s:",s);

 42         for(j = 1;j <= n;j ++)

 43         {

 44             if((len[j]-L) > 1)

 45             continue;

 46             if(len[j] == L)

 47             {

 48                 z = 0;

 49                 for(k = 0;k < L;k ++)

 50                 {

 51                     if(s[k] != word[j][k])

 52                     z ++;

 53                     if(z >= 2)

 54                     break;

 55                 }

 56                 if(z == 1)

 57                 printf(" %s",word[j]);

 58             }

 59             else if(len[j] > L)

 60             {

 61                 z = 0;

 62                 for(k = 0,k1 = 0;k < L;k ++,k1 ++)

 63                 {

 64                     if(s[k] != word[j][k1])

 65                     {

 66                         if(s[k] == word[j][k1+1])

 67                         k1 ++;

 68                         else

 69                         break;

 70                         z ++;

 71                     }

 72                 }

 73                 if(k == L&&k1 == len[j]&&z == 1)

 74                 printf(" %s",word[j]);

 75                 else if(k == L&&k1 == len[j]-1&&z == 0)

 76                 printf(" %s",word[j]);

 77             }

 78             else

 79             {

 80                 z = 0;

 81                 for(k = 0,k1 = 0;k < L;k ++,k1 ++)

 82                 {

 83                     if(s[k] != word[j][k1])

 84                     {

 85                         if(s[k+1] == word[j][k1])

 86                         k ++;

 87                         else

 88                         break;

 89                         z ++;

 90                     }

 91                 }

 92                 if(k == L&&k1 == len[j]&&z == 1)

 93                 printf(" %s",word[j]);

 94                 else if(k == L+1&&k1 == len[j]+1&&z == 1)//随便试了一组,这里就查出错了。。aaa aaaa

 95                 printf(" %s",word[j]);

 96             }

 97         }

 98         printf("\n");

 99     }

100     return 0;

101 }

 

 

你可能感兴趣的:(check)