Counter Class
Create a Counter class that keeps track of an integer value. It should support three operations:
increment(): adds 1 to the valuedecrement(): subtracts 1 from the valuegetValue(): returns the current value
The counter starts at 0. Read commands from stdin (one per line): inc, dec, or get. For each get command, print the current value on a new line.
Input
- Line 1: an integer N, the number of commands (0 <= N <= 2·10^4)
- Next N lines: a command (
inc,dec, orget)
Output
- For each
getcommand, print the current counter value on a separate line.
Examples
Input:
5
inc
inc
get
dec
get
Output:
2
1
Input:
4
dec
dec
dec
get
Output:
-3
Input:
1
get
Output:
0
Calling get before any inc/dec returns the starting value, 0.
Input:
5
inc
dec
inc
dec
get
Output:
0
Increments and decrements cancel out: the counter returns to 0.