#C14696. Cloud Storage Simulator
Cloud Storage Simulator
Cloud Storage Simulator
This problem requires you to implement a simple cloud storage system that supports multiple users. Each user can register, upload files, download files, delete files, and list all files stored under their account.
You are required to implement the following operations:
- register <username>: Registers a new user. If the username already exists, the program should output Username already taken.
- upload <username> <file_name> <file_content>: Uploads a new file for the given user. If the user does not exist, output User does not exist.
- download <username> <file_name>: Downloads a file and prints its content. If the user does not exist, output User does not exist.. If the file does not exist, output File does not exist.
- delete <username> <file_name>: Deletes the specified file. If the user does not exist, output User does not exist.. If the file does not exist, output File does not exist.
- list <username>: Lists all files for the user sorted in lexicographical order and prints them separated by a single space. If the user does not exist, output User does not exist.. If the user has no files, print an empty line.
Internally, you should simulate a cloud storage system. In your implementation, if an operation is invalid, you must output the corresponding error message exactly as specified.
Note: If an operation (like register, upload or delete) does not require any output upon success, simply do not output anything for that operation.
The operations are given as commands from standard input (stdin). Process them in order and print any outputs to standard output (stdout).
Mathematically, you can consider the system as a function mapping a user \( u \) to a set of pairs \( \{(f, c)\} \), where \( f \) is the file name and \( c \) is its content. The operations update these mappings as follows:
[ \texttt{register}(u):, S(u)=\emptyset \quad \text{if } u \notin S ] [ \texttt{upload}(u, f, c):, S(u)=S(u)\cup{(f,c)} \quad \text{if } u \in S ] [ \texttt{download}(u, f):, \text{return } c \quad \text{if } (f,c) \in S(u) ] [ \texttt{delete}(u, f):, S(u)=S(u)\setminus{(f,c)} \quad \text{if } (f,c) \in S(u) ]
Implement these operations accordingly.
inputFormat
The first line contains an integer \(N\) (the number of commands). The following \(N\) lines each contain a command. Each command is in one of the following formats:
register <username>
upload <username> <file_name> <file_content>
download <username> <file_name>
delete <username> <file_name>
list <username>
All file content values are single-word strings without spaces.
outputFormat
For each command, output the appropriate result:
- If the command is download, print the file content if successful or the error message if not.
- If the command is list, print all file names sorted lexicographically separated by a single space. If the user has no files, print an empty line. If the user does not exist, print the error message.
- For register, upload, and delete commands, output nothing if successful. In case of an error, print the specified error message exactly.
Error messages:
- Registering an already registered user:
Username already taken.
- Any operation with a non-existent user:
User does not exist.
- Download or delete for a non-existent file:
File does not exist.
6
register alice
upload alice file1.txt HelloWorld
download alice file1.txt
list alice
delete alice file1.txt
list alice
HelloWorld
file1.txt
</p>