#t8. BCD数转换修复

BCD数转换修复

BCD Number Conversion Fix

Problem Description

A BCD number uses one byte to represent a two-digit decimal number, with each group of four bits representing one digit. If a BCD number's hexadecimal is 0x12, it represents the decimal number 12. Xiao Ming mistakenly treated all BCD numbers as binary numbers and converted them to decimal for output; for example, the BCD 0x12 was output as the decimal number 18. Your program should read this wrong decimal number and output the correct decimal number.

Input Format

A single line gives a positive integer in the range [0,153][0, 153], guaranteed to be convertible back to a valid BCD number — that is, when this integer is converted to hexadecimal, no A–F digits will appear.

Output Format

Output the corresponding correct decimal number.

Sample Input 1

18

Sample Output 1

12

Sample Input 2

0

Sample Output 2

0

Sample Input 3

153

Sample Output 3

99

Constraints

The input integer is in the range 0≤n≤1530 \le n \le 153.

Hint

  • The hard part of this problem is understanding the statement: one byte holds two decimal digits (each taking 4 bits), so valid BCD numbers have an upper bound on the wrong value that gets printed — what is it?
  • To fix it, split the wrong value you read into two halves as if in hexadecimal (base 16), then reassemble them as decimal — / and % each handle one half.
  • Check against the samples: 18 → 12; 153 → 99.