首页 > 试题广场 >

Manipulate Inodes

[编程题]Manipulate Inodes
  • 热度指数:1 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解

    Given a list of bash commands to manipulate folders/files. Can you answer the results of a list of existence checking?

    Suppose we are under the empty root folder ‘/’. The commands include: mkdir [-p], touch and rm [-r], which are all BSD general commands. If you are not familiar with them, refer to command explanations (备注) after the output example. If the command cannot be executed correctly, just ignore this command.

    The questions are existFile or existFolder, which are described as below. A valid path can either be a file or folder, not both.
existFile path
    Check whether a file specified by path exists. Output ‘true’ if file exists, ‘false’ otherwise.
existFolder path
    Check whether a folder specified by path exists. Output ‘true’ if folder exists, ‘false’ otherwise.

输入描述:

The first line contains two integers m(1  m  1000) and n((1  n  100) – the number of commands and questions separately.The following m lines are the commands, followed by n lines of questions.



输出描述:
For each question, output “true” if the file/folder
exists or “false” otherwise.
示例1

输入

4 2
mkdir -p a/b/c
mkdir a/b/c/d/e
touch file1
rm -r a/b
existFolder /a/b
existFile /file1

输出

false
true

说明

1. We are in root folder ‘/’.
2. ‘/’ at the beginning of each path is optional.
3.Multiple sequential '/' is equal to one '/'.
4. The path string will only contain alphabetic characters, numbers, '_' or '/'.
5. Command options, -p and -r, will always occur before path string it they exist and there will only be one path string for each command.

备注:

NAME

     mkdir -- make directories

SYNOPSIS

     mkdir [-p] directory_name

DESCRIPTION

     The mkdir utilitycreates the directories named as operands.

     The options areas follows:

    -p      Create intermediatedirectories as required.  If this optionis not specified, the full path prefix of each operand must already exist.  On the other hand, with this optionspecified, no error will be reported if a directory given as an operand alreadyexists.


NAME

     touch -- change file access andmodification times

SYNOPSIS

     touch file

DESCRIPTION

    The touch utility sets themodification and access times of files. If any file does not exist, it is created with default permissions.


NAME

     rm -- remove directory entries

SYNOPSIS

     rm [-r] file

DESCRIPTION

    The rm utility attempts to remove the non-directory type filesspecified on the command line.

    The options are as follows:

    -r          Attempt to remove the file hierarchyrooted in the file argument.  The -roption implies the -d option.

这道题你会答吗?花几分钟告诉大家答案吧!