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使用减的方式安装系统.开箱即用的豪华版本,大部分人需要的都有了,同样包括个别用户不需要的,配置方面 ...
随机推荐
- css 自定义checkbox多选复选框样式
html: <input type="checkbox" id="" value="">菜单1 <input type=& ...
- mysql的length与char_length的区别
length: 是计算字段的长度一个汉字是算三个字符,一个数字或字母算一个字符 char_length:不管汉字还是数字或者是字母都算是一个字符 同时这两个函数,可用于判断数据中是否有中文文字 例 ...
- 使用 win10 的库来组织自己的同类文件
库相当于虚拟目录,可以把不同的文件夹包含起来. 找起东西来不用东奔西跑了...
- C程序设计语言笔记-第一章
The C Programming language notes 一 基础变量类型.运算符和判断循环 char 字符型 character ...
- win10 禁用自动更新
管理员身份运行CMD,输入REG add "HKLM\SYSTEM\CurrentControlSet\Services\UsoSvc" /v "Start" ...
- 洛谷九月月赛T1 思考
很迷的一道题目,刚开始直接枚举n个1,然后去mod m ,爆0,后来发现一个神奇性质:找到递推公式An=An-1*10+1,枚举n,不断mod m,每递推一次就1的个数加一.居然可行! 听说余数具有可 ...
- Java设计模式(7)——结构型模式之适配器模式(Adapter)
一.概述 概念 其实,举个生活中的例子的话,适配器模式可以类比转接头,比如typeC和USB的转接头,把原本只能接typeC的接口,拓展为可以接普通USB:这里的转接头一方面需要查在typeC上,一方 ...
- DevExpress通过girdcontrol实现分页
简介:DevExpress中如何实现GridControl的分页功能, 主要是利用DataNavigator和GridControl组合,自定义事件实现分页功能 接下来,我们就去实现分页功能,先看下效 ...
- 全国Uber优步司机奖励政策 (1月18日-1月24日)
本周已经公开奖励整的城市有:北 京.成 都.重 庆.上 海.深 圳.长 沙.佛 山.广 州.苏 州.杭 州.南 京.宁 波.青 岛.天 津.西 安.武 汉.厦 门,可按CTRL+F,搜城市名快速查找. ...
- 成都Uber优步司机奖励政策(3月26日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...