POJ-1035 Spell checker map标记

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

  方法很多,hash标记判重也可以,然后就是分情况判断就可以了。。

 1 //STATUS:C++_AC_360MS_1132KB

 2 #include<stdio.h>

 3 #include<stdlib.h>

 4 #include<string.h>

 5 #include<math.h>

 6 #include<iostream>

 7 #include<string>

 8 #include<algorithm>

 9 #include<vector>

10 #include<queue>

11 #include<stack>

12 #include<map>

13 using namespace std;

14 #define LL __int64

15 #define pii pair<int,int>

16 #define Max(a,b) ((a)>(b)?(a):(b))

17 #define Min(a,b) ((a)<(b)?(a):(b))

18 #define mem(a,b) memset(a,b,sizeof(a))

19 #define lson l,mid,rt<<1

20 #define rson mid+1,r,rt<<1|1

21 #define put1(i,j,num) (li[i][0]|=(num<<(j<<1)))

22 #define get1(i,j) ((li[i][0]&(3<<(j<<1)))>>(j<<1))

23 #define put2(i,j,num) (li[i][1]|=(num<<j))

24 #define get2(i,j) ((li[i][1]&(1<<j))>>j)

25 const int N=10010,INF=0x3f3f3f3f,MOD=1999997;

26 const LL LLNF=0x3f3f3f3f3f3f3f3fLL;

27 

28 map<string,int> q;

29 char s[N][20];

30 int len[N];

31 int n;

32 

33 int judge1(char *a,char *b,int len)

34 {

35     int i,cou=0;

36     for(i=0;i<len;i++){

37         if(a[i]!=b[i])cou++;

38         if(cou==2)return 0;

39     }

40     return 1;

41 }

42 

43 int judge2(char *a,char *b,int len)

44 {

45     int i,j,cou=0;

46     for(i=j=0;i<len;i++,j++){

47         if(b[j]!=a[i])j--,cou++;

48         if(cou==2)return 0;

49     }

50     return 1;

51 }

52 

53 int main()

54 {

55  //   freopen("in.txt","r",stdin);

56     int i,j,lent;

57     char st[20];

58     n=0;

59     q.clear();

60     while(++n){

61         scanf("%s",s[n]);

62         if(s[n][0]=='#'){n--;break;}

63         q[s[n]]=1;

64         len[n]=strlen(s[n]);

65     }

66     while(scanf("%s",st)){

67         if(st[0]=='#')break;

68         if(q[st])printf("%s is correct\n",st);

69         else{

70             lent=strlen(st);

71             printf("%s:",st);

72             for(i=1;i<=n;i++){

73                 if(lent==len[i] && judge1(s[i],st,lent))

74                     printf(" %s",s[i]);

75                 else if(lent==len[i]+1 && judge2(st,s[i],lent))

76                     printf(" %s",s[i]);

77                 else if(lent+1==len[i] && judge2(s[i],st,len[i]))

78                     printf(" %s",s[i]);

79             }

80             putchar('\n');

81         }

82     }

83     return 0;

84 }

 

你可能感兴趣的:(check)