#K46092. Basic File System Implementation

    ID: 27899 Type: Default 1000ms 256MiB

Basic File System Implementation

Basic File System Implementation

In this problem, you are required to implement a basic file system that supports four operations: create, read, write, and delete.

Each file is identified by a unique file name consisting of lowercase English letters only, with a maximum length of 100 characters. Each file stores an arbitrary string as its content (up to 1000 characters). All operations should ideally run in \(O(1)\) time.

The commands are provided via standard input. For operations that are successful (except read), no output is produced. If an operation fails (for example, trying to create an already existing file or operating on a non-existent file), print ERROR on its own line. For a read command, output the file's content if the file exists; otherwise, print ERROR.

inputFormat

The input begins with an integer \(N\) representing the number of operations. Each of the next \(N\) lines contains a command in one of the following formats:

  • create fileName
  • read fileName
  • write fileName content (Note: content may contain spaces)
  • delete fileName

outputFormat

For every operation that results in an error, output ERROR on a new line. For a successful read operation, output the file's content (which may be an empty string) on its own line. Do not output anything for successful create, write, or delete operations.

## sample
6
create file1
write file1 Hello
read file1
create file1
delete file1
read file1
Hello

ERROR ERROR

</p>