#C12244. File System Simulator

    ID: 41650 Type: Default 1000ms 256MiB

File System Simulator

File System Simulator

Implement a simple file system simulator that supports the following operations:

  • create <filename>: Create a new file with the given name. If the file already exists, output the error message: $$FileExistsError: File '' already exists.$$
  • write <filename> <data>: Write the provided data string to the specified file. If the file does not exist, output the error message: $$FileNotFoundError: File '' does not exist.$$
  • read <filename>: Read and output the contents of the specified file. If the file does not exist, output the error message: $$FileNotFoundError: File '' does not exist.$$
  • delete <filename>: Delete the specified file. If the file does not exist, output the error message: $$FileNotFoundError: File '' does not exist.$$

The file system should be maintained in memory, and only the read command and any error messages produce output. All input should be processed from standard input and all outputs should be printed to standard output.

inputFormat

The first line contains a single integer N representing the number of operations. Each of the next N lines contains a command in one of the following formats:

  • create <filename>
  • write <filename> <data> (the data string may contain underscores or alphanumeric characters without spaces)
  • read <filename>
  • delete <filename>

outputFormat

For each operation that produces an output:

  • If a read command is executed successfully, output the file's data on a new line.
  • If an operation fails (e.g., attempting to create an existing file, writing to a non-existent file, reading from a non-existent file, or deleting a non-existent file), output the corresponding error message on a new line.

There should be no other output.

## sample
5
create file1
create file1
write file1 Data1
read file1
delete file1
FileExistsError: File 'file1' already exists.

Data1

</p>