201309-3 字符串匹配

实现

#include <cstdio>
#include <cstring>

#define MAX_STR_LEN 0xff

char sub_str[MAX_STR_LEN];
char str[MAX_STR_LEN];
char str_cpy[MAX_STR_LEN];
int main() {
    
    scanf("%s",sub_str);

    int mode;
    scanf("%d",&mode);

    if (mode == 0) {
        for(int i = 0;i < strlen(sub_str);++i) {
            sub_str[i] = sub_str[i] | 0x20;
        }
    }

    int line_num;
    scanf("%d",&line_num);

    for (int i = 0;i < line_num;++i) {
        scanf("%s",str);

        if (mode == 1 && std::strstr(str, sub_str) != NULL) {
            printf("%s
",str);
        } else if (mode == 0 ){
            int j=0;
            for(j = 0;j < strlen(str);++j) {
                str_cpy[j] = str[j] | 0x20;
            }
            str_cpy[j] = 0;
            if (std::strstr(str_cpy,sub_str) != NULL) {
                printf("%s
",str);
            }
        }
    }


}
原文地址:https://www.cnblogs.com/amonqsq/p/13559171.html