#K85617. File Storage and Tag Query
File Storage and Tag Query
File Storage and Tag Query
You are given a file tagging system where you can add tags to files and query files based on their tags. Each file is identified by a unique integer file ID. There are two types of operations:
- Add Operation:
+ file_id tag
. This operation adds the specified tag to the file with the given ID. - Query Operation:
? tag1 tag2 ...
. This operation queries for all file IDs that have all the specified tags. The result should be the list of matching file IDs in ascending order, printed as space-separated numbers. If no file matches, outputNone
.
The input will be provided via standard input (stdin) with the following format:
n operation1 operation2 ... operationn
where n is the number of operations.
inputFormat
The first line contains an integer n
representing the total number of operations. Each of the next n
lines contains an operation in one of the following formats:
+ file_id tag
for adding a tag to a file.? tag1 tag2 ...
for querying files that have all the given tags.
All input is read from stdin.
outputFormat
For each query operation, output a single line containing the resulting file IDs in ascending order separated by a single space. If no file matches the query, output None
(without quotes). All output should be sent to stdout.
6
+ 1 design
+ 1 database
+ 2 design
+ 2 backend
+ 3 database
? design database
1
</p>