#P8824. Simulated Terminal

    ID: 21988 Type: Default 1000ms 256MiB

Simulated Terminal

Simulated Terminal

This problem requires you to simulate a simple terminal that supports file operations. The terminal must support the following commands:

  1. touch filename: Create a file named filename if it does not already exist.
  2. rm name: Remove the file named name if it exists.
  3. ls: List all existing (i.e. not deleted) files in the order of their creation.
  4. rename oldName newName: Rename the file oldName to newName if oldName exists and there is no file with the name newName.

All filenames consist solely of uppercase or lowercase English letters and are case-sensitive.

For each ls command, output the names of all current files separated by a single space. If no file exists, output an empty line.

Note that the order of the files is determined by the creation time. Renaming a file does not change its original creation order.

All formulas, if any, should be in LaTeX format; however, this problem does not require any formulas.

inputFormat

The first line contains an integer N representing the number of commands. The next N lines each contain one command. Each command is one of the following:

  • touch filename
  • rm name
  • ls
  • rename oldName newName

Filenames are non-empty strings consisting only of uppercase and lowercase English letters.

outputFormat

For every ls command encountered in the input, output one line showing all current filenames (i.e. not deleted) separated by a single space in the order of their creation. If there are no files, output an empty line.

sample

8
touch a
touch b
ls
rename a c
ls
rm b
ls
ls
a b

c b c c

</p>