首页 > 其他 > 详细

poj 1035(水题,枚举)

时间:2021-08-19 14:53:38      阅读:19      评论:0      收藏:0      [点我收藏+]
#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;
}

 

poj 1035(水题,枚举)

原文:https://www.cnblogs.com/stevenzrx/p/15161274.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!