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
#include<stdio.h>
#include<string.h>
int main()
{
int n,m,i,j,len1,len2,x,y,z;
int flag1=,pos,count;
char s1[][],s2[][];
while(scanf("%d",&n)!=EOF)
{
getchar();
for(i=; i<n; i++)///输入文件名
{
gets(s1[i]);
}
scanf("%d",&m);///输入搜索
getchar();
for(i=; i<m; i++)
{
gets(s2[i]);
}
for(i=; i<m; i++)
{
count=;
for(j=; j<n; j++)
{
len1=strlen(s1[j]);
len2=strlen(s2[i]) ;
for(x=; x<len2; x++)///查找星号标志
{
if(s2[i][x]=='*')
{
pos=x;///标记星号
break;
}
}
flag1=;
for(y=; y<pos; y++) ///左边
{
if(s1[j][y]!=s2[i][y])
{
flag1=;
break;
}
}
if(flag1)
{
continue;
}
for(z=; z<len2-pos; z++)///右边
{
if(s1[j][len1-z]!=s2[i][len2-z])
{
flag1=;
break;
}
}
if(flag1)
{
continue;
}
if(flag1==)
{
if(count>=)/// 输出含有逗号的多组结果,学习这种控制方法
printf(", %s",s1[j]);
else
printf("%s",s1[j]);
count++;
}
}
if(count==)
printf("FILE NOT FOUND");
printf("\n");
}
printf("\n");
}
return ;
}
File Searching的更多相关文章
- execve(file, argv, env)参数argv获取字符串个数
/* Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU ...
- Java性能提示(全)
http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...
- Linux 进程与信号的概念和操作
进程 主要参考: http://www.bogotobogo.com/Linux/linux_process_and_signals.php 信号与进程几乎控制了操作系统的每个任务. 在shell中输 ...
- 拼写纠错的利器,BK树算法
BK树或者称为Burkhard-Keller树,是一种基于树的数据结构,被设计于快速查找近似字符串匹配,比方说拼写纠错,或模糊查找,当搜索”aeek”时能返回”seek”和”peek”. 本文首先剖析 ...
- 转:pycharm community debug django projects
原文:https://automationpanda.com/2017/09/14/django-projects-in-pycharm-community-edition/comment-page- ...
- Linux 进程与信号的概念和操作 linux process and signals
进程 主要参考: http://www.bogotobogo.com/Linux/linux_process_and_signals.php 译者:李秋豪 信号与进程几乎控制了操作系统的每个任务. 在 ...
- 最新Mac安装CocoaPods详细教程及各种坑解决办法
网上有很多教程,但要么内容很老,要么不详细,要么各种坑的情况没写.最近买新电脑了,正好要走一遍这些流程,所以写下次教程. 一.安装RVM及更新Ruby 安装RVM的目的是为了更新Ruby,如果你的Ru ...
- Trie(前缀树/字典树)及其应用
Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,PATRICIA tree,以及bitwise版本的crit-bit tree.当然很多名字的意义其实有交 ...
- Arch系统软件列表
1. 安装统计 2. 安装列表 3. 安装说明 4. 作为依赖项的安装列表 5. 更正 mangaro使用减的方式安装系统.开箱即用的豪华版本,大部分人需要的都有了,同样包括个别用户不需要的,配置方面 ...
随机推荐
- mac appstore应用下载失败,不能更新等等问题,都可以解决
打开终端,输入以下命令 open `getconf DARWIN_USER_CACHE_DIR`/com.apple.appstore 进入目录,删除 com.apple.appstore  重启系 ...
- PHP程序员面试中经常被提问的问题【转载】
1. Include 与 require的区别,require和require_once的效率哪个高? Php在遇到include时就解释一次,如果页面中出现10次include,php就解释10次, ...
- 对Python语法简洁的贴切描述
很多人认为,Python与其他语言相比,具有语法简洁的特点.但这种简洁到底体现在哪些地方,很少有人能说清楚.今天看到一个对这一问题的描述,个人觉得很不错,原文如下: “Python语法主要用来精确表达 ...
- for循环练习题(1 ,判断任意一个数是91的多少倍 2,编写程序实现给定一个整数判断它从0到这个整数中间出现多少次9的次数)
1 //判断任意一个数是9的多少倍 #include <stdio.h> #include <stdlib.h> int main() { printf("请输入任意 ...
- linux 下安装 Cisco Packet Tracer 7.11以及一些注意
https://blog.csdn.net/qq_35882901/article/details/77652571 https://linux.cn/article-5576-1.html 开启登录 ...
- java 学习知识汇总
一:常见模式与工具 学习Java技术体系,设计模式,流行的框架与组件是必不可少的: 常见的设计模式,编码必备 Spring5,做应用必不可少的最新框架 MyBatis,玩数据库必不可少的组件 二:工程 ...
- 不使用IDE,用maven命令打包war项目及出现的问题解决(最全攻略,亲测有效)
第一次在博客园写博客,写的不好大家见谅啊!! 一.首先,在用maven打包之前,一定确认好你使用的jdk版本和maven的版本,最好就是用jdk1.8和maven3.3以上的,版本太低了容易出现一些意 ...
- 使用GeoServer发布shp数据为WMS服务和WFS服务
使用GeoServer发布shp数据为WMS服务和WFS服务 1安装GeoServer 2使用GeoServer上传数据 3使用GeoServer发布数据为WMS和WFS 看完本教程,你将学会安装Ge ...
- 成都Uber优步司机奖励政策(3月1日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 成都Uber优步司机奖励政策(1月18日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...