#K83062. File Path Operations

    ID: 36114 Type: Default 1000ms 256MiB

File Path Operations

File Path Operations

This problem involves implementing a set of file path operations similar to those provided by common operating system libraries. You are required to implement four operations: normalize, is_absolute, join, and basename.

The normalize function should remove redundant current directory (.) and parent directory (..) references as well as unnecessary slashes, producing a simplified version of the file path. For example, normalize("a/b/../c/./d") should return a/c/d.

The is_absolute function should check if a given file path is absolute, i.e. it starts with a forward slash /. It returns True if the path is absolute, otherwise False.

The join function should concatenate two file paths. If the second path is absolute, then its normalized form is returned; otherwise, the two paths are combined with a separating slash and then normalized.

The basename function returns the last portion of the file path. If the path ends with a slash, it should return an empty string.

You will be given multiple queries via standard input to perform these operations.

inputFormat

The input begins with an integer T (where T ≥ 1) on its own line representing the number of queries. Each of the following T lines contains a query. Each query starts with the operation name (normalize, is_absolute, join, or basename), followed by the required arguments separated by a space. For the join operation, there will be two arguments; for the other operations, only one argument is provided.

outputFormat

For each query, output the result of the corresponding operation on its own line. For is_absolute, output True or False. For basename, if there is no basename, output an empty line.

## sample
4
normalize a/b/../c/./d
is_absolute /a/b/c
join /a/b c/d
basename /a/b/c.txt
a/c/d

True /a/b/c/d c.txt

</p>