#C7217. Lunar Event Observation
Lunar Event Observation
Lunar Event Observation
Luna is an avid observer of lunar events. However, due to the mandatory 1-hour gap between consecutive events, her total observation time in a day is capped at 8
hours. Each event is represented by a character: P
denotes a partial lunar eclipse that takes 3
hours, and T
denotes a total lunar eclipse that takes 5
hours. In addition, a 1
-hour gap is added after every event except after the very last one if the cumulative time is less than 8
hours.
For example, given the sequence "PPT
", the calculation is as follows:
[ 3,(P) + 1,(gap) + 3,(P) + 1,(gap) + 5,(T) = 13 \text{ hours}, ]
but since the maximum allowed observation time is 8
hours, the output will be 8
.
inputFormat
The input is read from stdin and starts with an integer T
representing the number of test cases. This is followed by T
lines, each containing a string of characters (P
and T
) representing the sequence of lunar events for a day.
outputFormat
For each test case, output a single integer on a new line that represents the total observation time (in hours) for that day's events, with the maximum capped at 8
hours. The output is written to stdout.
8
PTP
PTPTPP
TTTTPPPT
P
T
PPP
TT
PPTT
8
8
8
3
5
8
8
8
</p>