bLue的文件查找器
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description
bLue 的电脑里存了各种各样的文件,随着文件越来越多,查找文件也成了一个麻烦事。
现在,他想要查找所有指定格式(扩展名)的文件,不过他并不会使用文件管理器自带的搜索功能,所以他想求你写一个文件查找器,来帮他查找所有指定格式的文件。
Input
输入数据有多组(数据组数不超过 100),到 EOF 结束。
对于每组数据:
•第一行输入一个整数 n (1 <= n <= 100) 和一个长度不超过 5 的字符串 ex,分别表示文件夹内的文件数量和要查找的文件的扩展名。
•接下来的 n 行,每行输入一个完整文件名。保证文件名不包含空格且长度不超过 100。
Output
对于每组数据,按照输入顺序输出文件夹内所有扩展名符合查找要求的文件名。
Sample Input
6 cpp
3717.cpp
xunhuansai_daima.zip
xunhuansai_jietibaogao.pdf
C.cpp
bLue.jpg
cyk_de_richang.mp4
Sample Output
3717.cpp
C.cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
int n;
char a[10];
while(scanf("%d%s",&n,a)!=EOF)
{
char b[101]= {0};
int i;
for(i=0; i<n; i++)
{
scanf("%s",b); //遍输入,遍判断
int len=strlen(b);
int j;
for(j=0; j<len; j++)
{
if(b[j]==’.’) //如果=.;
{
if(strcmp(a,b+j+1)==0) //则比较一下;
{
printf("%s\n",b);
break;
}
}
}
}
}
return 0;
}