#C104. Gemstone Tracker
Gemstone Tracker
Gemstone Tracker
You are given a series of commands to simulate a gemstone tracking system. Implement the class GemstoneTracker
which supports the following operations:
- Discover: Mark a gemstone as discovered. If the gemstone was previously misplaced, its state is restored.
- Misplace: Mark a gemstone as misplaced (i.e., remove it from the discovered set if present).
- Count: Return the current number of gemstones in the discovered set.
You are also required to process a sequence of commands. Each command is given as a string in one of the following formats:
D <gemstone_id>
: Discover the gemstone with the given ID.M <gemstone_id>
: Misplace the gemstone with the given ID.C
: Output the current count of discovered gemstones.
Your program should process these commands in order and print the results of each count operation.
Note: When a gemstone is rediscovered after being misplaced, it is added back to the discovered set.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
- The first line contains an integer n representing the total number of commands.
- The next n lines each contain a command. A command is one of the following formats:
D <gemstone_id>
(to discover a gemstone)M <gemstone_id>
(to misplace a gemstone)C
(to output the current count)
outputFormat
Whenever a command C
is encountered, output the current count of discovered gemstones on a new line to standard output (stdout).
6
D ruby01
D emerald02
C
M ruby01
C
D ruby01
2
1
</p>