// 本来不想写,因为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 }
 posted on 2011-05-15 12:31  eth0  阅读(127)  评论(0编辑  收藏  举报