编程介的小学生 2019-04-26 23:03 采纳率: 0.4%
浏览 91

文件搜索的工具的程序的编写,怎么利用C语言的程序的射击的方式来实现这里的程序的

Problem Description
WisKey downloaded much software in winter vacation, and the disk was in a state of confusion. He wastes many times to find the file everyday. So he wants a tool to help him do this work.
The file name consists of lowercase letters.
The name pattern is a string of lowercases, '?'s and '*'s. In a pattern, a '?' matches any single lowercase, and a '*' matches none or more lowercases.
Let’s do this~

Input
The first line of input contains two integers N (0 < N <= 10000) and M (0 < M <=100), representing the number of file names and the number of word patterns.
Each of the following N lines contains a file name. After those, each of the last M lines contains a name pattern.
You can assume that the length of patterns will not exceed 6, and the length of file names will not exceed 20.
There are multiple cases in the data file, process to end of file.

Output
For each pattern, print a line contains the number of matched file names.
If there is no file name that can match the pattern, print "Not match".

Sample Input
4 5
this
the
an
is
t*
?h*s
??e*
*s
e

Sample Output
2
1
1
2
Not match

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-09 04:13
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    这是一个简单的C语言程序,用于搜索文件名中包含特定模式的部分。程序使用了循环和字符串匹配的方法来找到所有符合条件的文件名。

    #include <stdio.h>
    #include <string.h>
    
    int main() {
        int n, m;
        scanf("%d %d", &n, &m);
        char fileName[20], pattern[10];
        for(int i = 0; i < n; i++) {
            fgets(fileName, sizeof(fileName), stdin);
            for(int j = 0; j < m; j++) {
                fgets(pattern, sizeof(pattern), stdin);
                int count = 0;
                int flag = 0;
                for(int k = 0; k < strlen(fileName); k++) {
                    if(flag == 1 && (pattern[k] != '*' || strcmp(fileName+k+1, pattern)) ) break;
                    else if(pattern[k] == '*') {
                        flag = 1;
                        continue;
                    } else {
                        if(pattern[k] == '?') {
                            if(k+1 < strlen(fileName))
                                if(islower(fileName[k+1])) count++;
                        }
                    }
                }
                printf("%d\n", count);
            }
        }
    
        return 0;
    }
    

    这个程序首先读入两个整数N和M,表示文件数量和模式的数量。然后,它将输入到一个文件中,每个文件以字符串形式表示,包括文件名称和模式。程序遍历所有的文件和模式,并计算符合模式的文件数量。

    注意:这个程序没有处理空格的情况,如果文件名中有空格,你需要在输入文件时加上相应的处理。此外,这个程序也没有处理大写和小写字母的问题,如果你需要处理这些情况,你可能需要修改程序以适应你的需求。

    评论

报告相同问题?