#C8163. Elevator Simulator
Elevator Simulator
Elevator Simulator
This problem involves simulating an elevator's movement in a building starting from the ground floor (0). You are given a string of commands where each character represents a move. The command U
instructs the elevator to move up one floor, and the command D
instructs it to move down one floor. However, the elevator can never go below the ground floor (0).
The movement of the elevator can be described by the recurrence formula: \[ f_0 = 0, \quad f_i = \begin{cases} f_{i-1} + 1, & \text{if the command is } U,\\ \max(0, f_{i-1} - 1), & \text{if the command is } D. \end{cases} \]
Your task is to compute and output the final floor after processing all commands.
inputFormat
The input consists of a single line containing a non-empty string composed solely of the characters 'U' and 'D'. This string represents the sequence of commands for moving the elevator.
outputFormat
Output a single integer which is the final floor number after executing all the commands. The output should be sent to standard output.
## sampleUUUU
4