Demerit Points (DemeritPoints)
InterviewTime limit0.1sMemory limit32 MB
Simulate a student's demerit events encoded as base-36 chars, tracking accumulated points and quotient-by-10 crossing, and output total expulsion weeks plus weapon or permanent marker.
- Level
Medium5 of 10
- Topics
- Simulation, String, Math, Implementation
- Solved
- No attempts yet
Problem
Students of Seolgwak live on demerit points, mostly from the Uiheng Hall, and sometimes end up expelled, the flower of dormitory life. Each time they receive demerit points they can join a point-reduction program, but if they pile up many points at once, say by sleeping again in the fourth-floor senior's room, skipping roll call, and skipping the first-period physics class, their points pass 10 and they are expelled. Even if that person is the top student!
As the students of Seolgwak well know, the demerit point and expulsion rules of Seolgwak are as follows.
- When you receive X demerit points, X points are added to your accumulated demerit points.
- If adding X points increases the quotient of the accumulated demerit points divided by 10, you are expelled. If this quotient is 1, 2, or 3, you are expelled for 1, 2, or 3 weeks; if it is 4, you receive a weapon expulsion; if it is greater than 4, you receive a permanent expulsion.
- Once you receive a weapon expulsion or a permanent expulsion, you cannot re-enter the Uiheng Hall and cannot receive more demerit points.
Now, using the given data, compute in weeks how many total weeks the owner of the demerit points is expelled. Assume that during the expulsion period no demerit points are received, and that after the expulsion ends demerit points start being received again.
For reference, the ASCII codes of 0~9 are 48~57, and the ASCII codes of A~Z are 65~90.
Input
The first line gives the number of students N (N ≤ 20) whose expulsion periods must be computed.
From the second line, N lines follow, each giving the information of one student. Each line gives, as a string with no spaces, the demerit points one student received in order. Demerit points from 0 to 9 are given as the digits 0 ~ 9, and demerit points from 10 to 35 are given as the uppercase letters A ~ Z. The length of this string does not exceed 30.
For example, if the input B1A4 is given, the student received 11 points, 1 point, 10 points, and 4 points in that order.
Output
For each student, output the total period they are expelled, in weeks, one student per line.
If a student receives a weapon expulsion or a permanent expulsion, output the expulsion period, then append (weapon) for a weapon expulsion or (09) for a permanent expulsion, with no space and including the parentheses; this is not included in the expulsion period.