Question
Binary C Program The first line of input will be the number of total instructions (file/directory creations and deletes and queries). The instructions will follow,
Binary C Program
The first line of input will be the number of total instructions (file/directory creations and deletes and queries). The instructions will follow, one per line. Each instruction will be several space separated tokens. The syntax for each instruction in the input is as follows: All create instructions will start with the integer 1. This will be followed by a string designating the location in the directory/file structure this item will be in. This string will be a sequence of 1- 100 characters from the set {'L', 'R'}. This string will be followed by the name of the file or directory. If the item is a directory, the name will be the last character of the location string. If the item is a file, it will be the name of the file (in between 2 and 19 characters long, as previously designated). Thus, you can differentiate between a file and a directory by the length of the name. This will be followed by an integer, representing the size of the item in bytes. Though a create may initially make an empty directory, these directories will later be filled with at least one item. All delete instructions will start with the integer 2. This will be followed by a string designating the location in the directory/file structure this item is at. This string will be a sequence of 1-100 characters from the set {'L', 'R'}. (So we never delete the root directory.) Also, deletes will be such that they never leave empty directories. All queries for the number of files in a directory will start with the integer 3. This will be followed by a string designating the location of the directory. If the directory is a subdirectory of the root, this string will be a sequence of 1-100 characters from the set {'L', 'R'}. If the query is for the root directory, the string will be "C". You will always be given a string that corresponds to the location of a directory for this type of query. All queries for the number of subdirectories in a directory will start with the integer 4. This will be followed by a string designating the location of the directory. If the directory is a subdirectory of the root, this string will be a sequence of 1-100 characters from the set {'L', 'R'}. If the query is for the root directory, the string will be "C". You will always be given a string that corresponds to the location of a directory for this type of query. Note that this value could be zero, if the directory queried stores either 1 or 2 files. All queries for the total size of a file/directory will start with the integer 5. This will be followed by a string designating the location of the file/directory. If the directory is a subdirectory of the root or a file, this string will be a sequence of 1-100 characters from the set {'L', 'R'}. If the query is for the root directory, the string will be "C". You will always be given a string that corresponds a valid item in the directory structure. If the item is a directory, add up the sizes of each item (in bytes) in the subtree of this directory, including the directory itself. If the item is a file, just return the size of that file (in bytes).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started