A - ボウリングの記録 / Bowling Record Editorial by admin Editorial for printing
swe-2-highEditorial
Each throw’s pin count \(A_i\) must be converted into a single character: X when \(A_i = 10\), - when \(A_i = 0\), and the digit character for values \(1\) through \(9\).
The program builds an answer string s by reading the counts one at a time and appending the matching character chosen with a ternary conditional. The expression char('0' + a) is a standard idiom: adding a to the character code of '0' produces the digit character for a.
Why it is correct: every possible value \(0 \leq A_i \leq 10\) falls into exactly one of the three cases and maps to the right symbol, and characters are appended in input order, so the resulting string is precisely the record from the first throw onward.
Each conversion is \(O(1)\), giving \(O(N)\) time overall. The input is consumed without being stored, and the output string s uses \(O(N)\) space.
posted:
last update: