File Searching(文件查找)1183

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

描述

你有没有使用操作系统提供的文件搜索工具?例如,在DOS中,如果你输入“dir * .exe”,操作系统会在当前目录中列出所有带有扩展名“exe”的可执行文件。这些日子里,你对你正在使用的蹩脚操作系统非常生气,你决定编写一个你自己的操作系统。当然,你想在你的操作系统中实现文件搜索功能。

输入

输入包含多个测试用例。连续的测试用例由空行分隔。每个测试用例都以整数N(1 <= N <= 100)开始,即当前目录中的文件数。然后N行,每行只有一个由小写字母('a'..'z')和点('。')组成的字符串,这是文件的名称。然后有一个整数M(1 <= M <= 20),即查询数量。M行跟随,每个行都有一个查询字符串,只包含小写字母,点号和星号('*')字符。请注意,星号是“通用匹配字符”,用于表示不确定的零个或多个字符。一开始,你只想写一个简单版本的文件搜索,所以每个字符串不能超过64个字符,查询字符串中只有一个星号字符。处理到文件结束(EOF)。

产量

对于每个测试用例,为每个查询的结果生成一行。用逗号(',')和空白('')字符在结果中分隔文件名。一个查询结果中的文件名应根据它们在输入中出现的顺序列出。如果没有匹配的文件,输出“FILE NOT FOUND”(不带引号)。用空行分隔两个连续的测试用例,但不要在最后一行之后输出额外的空白行。

strstr(str1,str2) 函数用于判断字符串str2是否是str1的子串。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
struct pin
{
    char first[100];
    char last[100];
} c[100];
int main()
{
    int m,n;
    char a[100][100],b[100][100];
    int i,j,k,s=0;
    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].last)<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;
}

猜你喜欢

转载自blog.csdn.net/qq_38984851/article/details/80213972