*spell checker<pku 1035>

 
  
 // 本来不想写,因为g没想到什么好方法,但是充数还是需要的... = =!
1 Source Code
2
3 Problem: 1035 User: eth1
4 Memory: 760K Time: 485MS
5 Language: C ++ Result: Accepted
6
7 Source Code
8 #include < iostream >
9 #include < string >
10 #include < cmath >
11 #include < algorithm >
12 #include < cstdio >
13 using namespace std;
14 string a[ 10005 ],b[ 55 ],ans[ 10001 ];
15 bool check( string x, string y)
16 {
17 int len1 = x.size();
18 int len2 = y.size();
19 if (abs(len1 - len2) > 1 ) return 0 ;
20 if (len1 == len2)
21 {
22 int ans = 0 ;
23 for ( int i = 0 ;i < len2;i ++ )
24 {
25 if (x[i] != y[i])
26 {
27 ans ++ ;
28 if (ans > 1 ) return 0 ;
29 }
30
31 }
32 /// if(ans>1) return 0;
33 return 1 ;
34 }
35 else if (len1 > len2)
36 {
37 int ans = 0 ;
38 for ( int i = 0 ,j = 0 ;i < len1 && j < len2;)
39 {
40 if (x[i] != y[j])
41 {
42 i ++ ;
43 ans ++ ;
44 if (ans > 1 ) return 0 ;
45 }
46 else
47 {
48 i ++ ;
49 j ++ ;
50 }
51 }
52 /// if(ans>1) return 0;
53 return 1 ;
54 }
55 else
56 {
57 int ans = 0 ;
58 for ( int i = 0 ,j = 0 ;i < len1 && j < len2;)
59 {
60 if (x[i] != y[j])
61 {
62 j ++ ;
63 ans ++ ;
64 if (ans > 1 ) return 0 ;
65 }
66 else
67 {
68 i ++ ;
69 j ++ ;
70 }
71 }
72 /// if(ans>1) return 0;
73 return 1 ;
74 }
75 }
76 int main()
77 {
78 string s;
79 int n = 0 ,m = 0 ;
80 while (cin >> s && s[ 0 ] != ' # ' )
81 {
82 a[n ++ ] = s;
83 }
84 while (cin >> s && s[ 0 ] != ' # ' )
85 {
86 b[m ++ ] = s;
87 }
88 for ( int i = 0 ;i < m;i ++ )
89 {
90 int k = 0 ,flag = 0 ;
91 for ( int j = 0 ;j < n;j ++ )
92 {
93 if (b[i] == a[j])
94 {
95 flag = 1 ;
96 cout << b[i] << " is correct " << endl;
97 break ;
98 }
99 else
100 {
101 if (check(b[i],a[j]))
102 ans[k ++ ] = a[j];
103 }
104 }
105 if ( ! flag)
106 {
107 cout << b[i] << ' : ' ;
108 for ( int j = 0 ;j < k;j ++ )
109 cout << ' ' << ans[j];
110 printf( " \n " );
111 }
112 }
113 return 0 ;
114 }

转载于:https://www.cnblogs.com/eth0/archive/2011/05/15/2046832.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值