#C14811. Zoo Animal Management
Zoo Animal Management
Zoo Animal Management
You are in charge of managing a zoo's animal population. Your task is to implement a system that processes two types of operations:
- add <type> <count>: Add a given number of animals of a specific type to the zoo. If the animal type does not exist, it is added to the zoo with the given count; otherwise, its count is increased by the specified amount.
- count <type>: Output the current total number of animals of the given type. If the animal type does not exist, output 0.
The commands are provided via standard input, and the results of the count
operations should be written to standard output. The number of operations can be large, so efficient handling is required.
Example:
Input:
6
add Lion 5
count Lion
add Tiger 3
count Tiger
add Lion 2
count Lion
Output:
5
3
7
Note: Use stdin
for input and stdout
for output. If any mathematical notation is needed, express it in LaTeX format (for example, $1 \le n \le 10^5$).
inputFormat
The first line contains a single integer $n$ ($1 \le n \le 10^5$), the number of commands.
Each of the next $n$ lines contains one command in one of the following formats:
add <type> <count>
: where<type>
is a string representing the animal type and<count>
is an integer ($0 \le count \le 10^9$).count <type>
: where<type>
is a string representing the animal type.
All commands are provided via standard input.
outputFormat
For each count
command, output a single line with the current count for the specified animal type. If the animal type has not been previously added, output 0.
6
add Lion 5
count Lion
add Tiger 3
count Tiger
add Lion 2
count Lion
5
3
7
</p>