Final Grade
InterviewTime limit2sMemory limit1024 MB
Given a string of letter grades (A is best, Z worst), output the mean rounded in the student's favor, capped at one step better than the worst grade.
- Level
Easy2 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Statement
Magizoologist Newt Scamander asks Jacob Kowalski, a non-magical person, how ordinary schools for non-magical people work. While telling the story, Jacob remembers his least favorite teacher. What he hated most was her way of calculating the final grade.
During the semester, each student received various grades written as Latin letters from A to Z. A is the best grade and Z is the worst. To compute the final grade, the teacher took the arithmetic mean of all grades received during the semester and rounded it in the student's favor using ordinary rounding rules. However, in her subject, a final grade could not be more than one step better than the worst grade received during the semester.
Input
A single line contains a non-empty string of uppercase Latin letters, whose length does not exceed 100. Each character of the string is one grade received during the semester.
Output
Print one character, the final grade for the semester.
Hints
In the first input, the arithmetic mean rounds to B. In the second input, despite the mean, the final grade cannot be more than one step better than Z. In the third input, there are equally many A and B grades, so the mean rounds to A.