zoukankan      html  css  js  c++  java
  • 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



     1 #include<stdio.h>
     2 #include<string.h>
     3 int main()
     4 {
     5     int n,m,i,j,len1,len2,x,y,z;
     6     int flag1=0,pos,count;
     7     char s1[110][70],s2[110][70];
     8     while(scanf("%d",&n)!=EOF)
     9     {
    10         getchar();
    11         for(i=0; i<n; i++)///输入文件名
    12         {
    13             gets(s1[i]);
    14         }
    15         scanf("%d",&m);///输入搜索
    16         getchar();
    17         for(i=0; i<m; i++)
    18         {
    19             gets(s2[i]);
    20         }
    21         for(i=0; i<m; i++)
    22         {
    23             count=0;
    24             for(j=0; j<n; j++)
    25             {
    26                 len1=strlen(s1[j]);
    27                 len2=strlen(s2[i]) ;
    28                 for(x=0; x<len2; x++)///查找星号标志
    29                 {
    30                     if(s2[i][x]=='*')
    31                     {
    32                         pos=x;///标记星号
    33                         break;
    34                     }
    35                 }
    36                 flag1=0;
    37                 for(y=0; y<pos; y++) ///左边
    38                 {
    39                     if(s1[j][y]!=s2[i][y])
    40                     {
    41                         flag1=1;
    42                         break;
    43                     }
    44                 }
    45                 if(flag1)
    46                 {
    47                     continue;
    48                 }
    49                 for(z=1; z<len2-pos; z++)///右边
    50                 {
    51                     if(s1[j][len1-z]!=s2[i][len2-z])
    52                     {
    53                         flag1=1;
    54                         break;
    55                     }
    56                 }
    57                 if(flag1)
    58                 {
    59                     continue;
    60                 }
    61                 if(flag1==0)
    62                 {
    63                     if(count>=1)/// 输出含有逗号的多组结果,学习这种控制方法
    64                         printf(", %s",s1[j]);
    65                     else
    66                         printf("%s",s1[j]);
    67                     count++;
    68                 }
    69             }
    70             if(count==0)
    71                 printf("FILE NOT FOUND");
    72             printf("
    ");
    73         }
    74         printf("
    ");
    75     }
    76     return 0;
    77 }  
  • 相关阅读:
    [React Hooks长文总结系列三]为所欲为,制作“穷人版”的redux
    [React Hooks长文总结系列二]渐入佳境,性能调优与自定义钩子
    [React Hooks长文总结系列一]初出茅庐,状态与副作用
    EsModule VS CommonJS
    [清代八股文]Promise如何实现串行执行
    React Fiber基本工作原理
    深入剖析setState同步异步机制
    破译《碟中谍》经典画面,解密指纹验证+刷脸!
    如何测试重签名的应用功能是否正常
    图像处理之滤镜、图文排版的开发详解,从入门到起飞
  • 原文地址:https://www.cnblogs.com/wkfvawl/p/8734345.html
Copyright © 2011-2022 走看看