其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
acm.jlu.edu.cn-2005-The Dir Command

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

The Dir Command
We all know the dos command "dir" . It can list the files in the computer . When we use the file
name with "?" , "*" as the parameter , it can list the files you need .

Input Specification

There are several lines (at most 100) each contain a file name and terminated by a line containing '*' .
Then a line contains a integer N and followed N lines . Each line contain a command "dir" with parameter.

Output Specification

For each "dir" print the result , each file name in a line in lower case . If nothing found print
"no such files" in a single line . Print a blank line after each result . Note that the command "dir" will
treat the capital letter and small letter as the same .

Sample Input

autoexec.bat
boot.ini
bootfont.bin
config.sys
io.sys
msdos.sys
pagefile.sys
*
4
dir autoexec.bat
dir boot*.*
dir ??.sys
dir *.*

Sample Output

autoexec.bat

boot.ini
bootfont.bin

io.sys

autoexec.bat
boot.ini
bootfont.bin
config.sys
io.sys
msdos.sys
pagefile.sys




开始打算只用C的 后来发现对输入的了解不够 没办法了



#include<cstdio> #include<iostream> #include<cstring> using namespace std; void main() { char files[100][20]; int idx=0; int idxf=0; char ch; scanf("%c",&ch); while(ch!='*') { if(ch>='A'&&ch<='Z') ch='a'+ch-'A'; files[idxf][idx++]=ch; if(ch=='\n') { files[idxf][idx]='\0'; idx=0; idxf++; } ch=getchar(); } int n; scanf("%d\n",&n); for(int i=0;i<n;i++) { char com[20];//输入的命令保存在com cin>>com;//滤掉dir cin>>com; for(int j=0;j<strlen(com);j++) if(com[j]>='A'&&com[j]<='Z') com[j]='a'+com[j]-'A'; bool found=false; for(int j=0;j<idxf;j++) { int p=0,q=0;//p指向当前一个文件名中字字符,q指向命令中的字符 L1: if(files[j][p]==com[q])//字符相等,pass { p++;q++; goto L1; } if(files[j][p]=='\n'&&strlen(com)==q)//两个字符串同时到头了,ok { printf("%s",files[j]); found=true; continue; } if(com[q]=='*')//'*'的匹配 { if(com[q+1]=='\0')//如果*是命令的最后一个字符,ok { cout<<files[j]; found=true; continue; } while(p<strlen(files[j])&&files[j][p]!=com[q+1])//匹配多个字符,直到有相同字符 p++; q++; goto L1; } if(files[j][p]!='\n'&&com[q]=='?')//匹配?,要保证文件名没到结束 { p++;q++; goto L1; } } if(!found) printf("no such files\n"); cout<<endl; } }



相关文章

相关软件