题目: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 }