poj 1035(水題,列舉)
阿新 • • 發佈:2021-08-19
#include<iostream> #include<cstdio> #include<cstring> using namespace std; char data[10005][20],t[20],ans[10005][20]; int cnt_ans,count; void cmp(){ int i,j,k,l; for(i=0;i<count;i++){ int len_d = strlen(data[i]); int len_t = strlen(t); if(len_d==len_t){int sum = 0; for(j=0;j<len_d;j++){ if(data[i][j]!=t[j]){ sum++; } } if(sum==1){ strcpy(ans[cnt_ans++],data[i]); } } else if(len_d==len_t-1){ for(j=0,l=0,k=0;k<len_t;k++,j++){if(data[i][j]==t[k]){ l++; } else{ j--; } } if(l==len_d){ strcpy(ans[cnt_ans++],data[i]); } } else if(len_d-1==len_t){ for(j=0,k=0,l=0;k<len_d;j++,k++){if(data[i][k]==t[j]){ l++; } else{ j--; } } if(l==len_t){ strcpy(ans[cnt_ans++],data[i]); } } } } int main(){ count = 0; while(scanf("%s",t)==1&&t[0]!='#'){ strcpy(data[count++],t); } l1: while(scanf("%s",t)==1&&t[0]!='#'){ for(int i=0;i<count;i++){ if(strcmp(t,data[i])==0){ printf("%s is correct\n",t); goto l1; } } cnt_ans = 0; cmp(); printf("%s:",t); for(int i=0;i<cnt_ans;i++){ printf(" %s",ans[i]); } printf("\n"); } return 0; }