#K11821. File Management System

    ID: 23554 Type: Default 1000ms 256MiB

File Management System

File Management System

You are required to implement a file management system that supports four commands: CREATE, DELETE, RENAME, and LIST. The system maintains a set of filenames and executes commands as described below:

  • CREATE filename: Create a new file with name filename. If the file already exists, do nothing.
  • DELETE filename: Delete the file with name filename. If the file does not exist, do nothing.
  • RENAME old_filename new_filename: Rename the file from old_filename to new_filename. This operation succeeds only if old_filename exists and new_filename does not exist; otherwise, do nothing.
  • LIST: List all filenames in the system in lexicographical order. Output the filenames separated by a single space. If no file exists, output an empty line.

Note: The commands are processed sequentially. Every time a LIST command is encountered, the current state of the file system (i.e. the sorted list of filenames) should be printed.

The operations of the file management system can be visualized as follows:

$$\text{If } A \text{ is the set of filenames, then after a command, the following updates occur:}$$

  • \( CREATE:\; A = A \cup \{filename\} \)
  • \( DELETE:\; A = A \setminus \{filename\} \)
  • \( RENAME:\; \text{if } old\_filename \in A \text{ and } new\_filename \notin A, \text{ then } A = \left(A \setminus \{old\_filename\}\right) \cup \{new\_filename\} \)

Implement the solution by reading commands from standard input and writing the required outputs to standard output.

inputFormat

The first line of input contains a single integer N (1 ≤ N ≤ 1000), representing the number of commands. The following N lines each contain one command in one of the following formats:

  • CREATE filename
  • DELETE filename
  • RENAME old_filename new_filename
  • LIST

Each filename is a non-empty string without spaces.

outputFormat

For each LIST command encountered in the input, print a line containing the filenames sorted in lexicographical order, separated by a single space. If no files exist at the time of the LIST command, print an empty line.

## sample
2
CREATE file1
LIST
file1

</p>