#K81272. Simple File System Simulator

    ID: 35717 Type: Default 1000ms 256MiB

Simple File System Simulator

Simple File System Simulator

You are required to implement a simple file system simulator. The file system is initialized with a total capacity (in bytes). It supports the following operations:

  • add filename filesize: Add a file with a given name and size, if there is enough space. If adding the file exceeds the total capacity, print Error: Not enough space.. Additionally, if a file with the same name already exists, print Error: File already exists..
  • del filename: Delete a file by name, if it exists.
  • info: Output the current used capacity over the total capacity in the format used/total.

The available operations will be provided in order. When an add command fails due to insufficient space (or duplicate file), an error message is printed immediately. The info command prints the current usage. The relationship for the capacity is given by the inequality \[ used + file\_size \le total\_capacity \] where used is the current used capacity, and file_size is the size of the file to be added.

inputFormat

The input is read from stdin and has the following format:

  1. The first line contains an integer total_capacity denoting the total capacity of the file system in bytes.
  2. The second line contains an integer n representing the number of operations.
  3. The next n lines each contain one operation. Each operation is either:
    • add file_name file_size
    • del file_name
    • info

outputFormat

For each operation that generates output (info commands and failed add commands), print the result on a new line to stdout.

The info command outputs the current used capacity and total capacity in the format used/total.

## sample
100
6
add file1 30
add file2 50
info
add file3 40
del file1
info
80/100

Error: Not enough space. 50/100

</p>