File Searching(水题,文件查找)

 

Description

Have you ever used file searching tools provided by an operating system? For example, in DOS, if you type "dir *.exe", the OS will list all executable files with extension "exe" in the current directory. These days, you are so mad with the crappy operating system you are using and you decide to write an OS of your own. Of course, you want to implement file searching functionality in your OS.

Input

The input contains several test cases. Consecutive test cases are separated by a blank line. Each test case begins with an integer N (1 <= N < =100), the number of files in the current directory. Then N lines follow, each line has one string consisting of lowercase letters ('a'..'z') and the dot ('.') only, which is the name of a file. Then there is an integer M (1 <= M <= 20), the number of queries. M lines follow, each has one query string consisting of lowercase letters, the dot and the star ('*') character only. Note that the star character is the "universal matching character" which is used to represent zero or numbers of characters that are uncertain. In the beginning, you just want to write a simple version of file searching, so every string contains no more than 64 characters and there is one and only one star character in the query string. Process to the End Of File (EOF).

Output

For each test case, generate one line for the results of each query. Separate file names in the result by a comma (',') and a blank (' ') character. The file names in the result of one query should be listed according to the order they appear in the input. If there is no matching file, output "FILE NOT FOUND" (without the quotation) instead. Separate two consecutive test cases with a blank line, but Do NOT output an extra blank line after the last one.

Sample Input

4
command.com
msdos.sys
io.sys
config.sys
2
com*.com
*.sys

3
a.txt
b.txt
c.txt
1
*.doc

Sample Output

command.com
msdos.sys, io.sys, config.sys

FILE NOT FOUND
题意:已知文件名的某部分,查找出包含这一部分的文件名,全部输出,若没有,则输出“FILE NOT FOUND”。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
struct pin
{
    char first[110];
    char last[110];
} c[110];
int main()
{
    int n,i,k,m,s,j;
    char a[110][110],b[110][110];
    while(~scanf("%d",&m))
    {
        for(i=0; i<m; i++)
        {
            scanf("%s",a[i]);
        }
        scanf("%d",&n);
        for(i=0; i<n; i++)
        {
            s=0;
            scanf("%s",b[i]);
            for(j=0; b[i][j]!='*'; j++)
                c[i].first[j]=b[i][j];
            j++;
            for(k=0; b[i][j]!='\0'; k++,j++)
                c[i].last[k]=b[i][j];
            if(strlen(c[i].first)+strlen(c[i].first)<strlen(a[i]))
                for(k=0; k<m; k++)
                {
                    if(strstr(a[k],c[i].first)&&strstr(a[k],c[i].last))
                    {
                        if(s!=0)
                            printf(", ");
                        printf("%s",a[k]);
                        s++;
                    }
                }
            if(s!=0)
                printf("\n");
        }
        if(s==0)
            printf("FILE NOT FOUND\n");
        printf("\n");
    }
    return 0;
}

萌新代码,有错误请多包涵^_^!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值