acm.jlu.edu.cn-2005-the Dir Command

xiaoxiao2021-03-06  70

The Dir Commandwe All Know The Dos Command "Dir". IT CAN List The file name with "?", "*" As the parameter, it can list the files you need. Input SpecificationThere 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 containa command "dir" with parameter. Output SpecificationFor each "dir" print the result, each file name in a line in lower case. If nothing foundprint "no such files" in a single line. Print a blank line after each result. Note thatthe command "dir" will treat the capital letter and small letter as The Same. Same. Sample InputAutoExec.bat

Boot.ini

Bootfont.bin

Config.sys

IO.sys

Msdos.sys

Pagefile.sys

*

4

Dir autoexec.bat

DIR boot *. *

DIR ??. sys

DIR *. *

Sample OutputautoExec.bat

Boot.ini

Bootfont.bin

IO.sys

Autoexec.bat

Boot.ini

Bootfont.bin

Config.sys

IO.sys

Msdos.sys

Pagefile.sys

I started to use C later discovered that I can't understand the input. I can't do it. #Include

#include

#include

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 [IDX] [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

{

CHAR COM [20]; / / Enter command Save in COM

Cin >> COM; // filter out DIR

Cin >> COM;

For (int J = 0; J = 'A' && COM [J] <= 'Z')

COM [J] = 'A' COM [J] - 'A';

Bool Found = false;

For (int J = 0; j

{

INT P = 0, q = 0; // P Points the word characters in the current file name, Q Points the characters in the command

L1: IF (files [j] == COM [q]) // Character is equal, Pass

{

P ; Q ;

Goto L1;

}

IF (files [j] == '/ n' && strlen (com) == q) // two strings at the same time, OK

{

Printf ("% s", files [j]);

Found = True;

CONTINUE;

}

IF (COM [q] == '*') // '*' matches

{

IF (COM [q 1] == '/ 0') // If * is the last character of the command, OK

{

Cout << Files [J];

Found = True;

CONTINUE;

}

While (P

P ;

Q ;

Goto L1;

}

IF (files [j]! = '/ n' && com [q] == '?') // match? To ensure that the file name is not over

{

P ; Q ;

Goto L1;

}

}

IF (! Found)

Printf ("No Such Files / N");

Cout << Endl;

}

}

转载请注明原文地址:https://www.9cbs.com/read-85907.html

New Post(0)