周宝贝周宝贝吧 关注:5贴子:280
  • 0回复贴,共1
Problem statement
Write a program which reads in a sequence of numbers and then converts each value to a Strange-Yet-Simple Roman Numeral. The rules for Strange-Yet-Simple Roman Numerals are as follows:
The character 'H' has value 200.
The character 'O' has value 100.
The character 'L' has value 20.
The character 'I' has value 4.
The character 'J' has value 2.
The character 'U' has value 1.
The character 'H' appears first (or not at all) and can occur any number of times.
The character 'O' is next and can occur at most one time.
The character 'L' is next and can occur at most 4 times.
The character 'I' is next and can occur at most 4 times.
The character 'J' is next and can occur at most one time.
The character 'U' is next and can occur at most one time.
Following these rules, there is only one way to encode a given value as a Strange-Yet-Simple Roman Numeral.
Input
The input begins with a single positive integer
n
which appears on a line by itself. This describes the number of values which must be converted. This is followed
n
or more lines with a single value
i
on each line. (Note that only the first
n
values must be handled. Ignore any extra data.)The value of
n
is relatively small (less than ten thousand). Each value
i
is also positive and relatively small (less than ten thousand).
Output
Each value
i
must be converted to a Strange-Yet-Simple Roman Numeral and then printed an a line by itself.Do NOT add unnecessary space or other material. See the sample input.
Sample Input
4
99999
34
17
27
34
22
Sample Output
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHOLLLLIIIIJU
LIIIJ
IIIIU
LIJU
NOTE CAREFULLY: Pay close attention to spaces and punctuation. Your program must produce exactly the required output (nothing extra) and DETAILS COUNT. The sample input and output are often suggestive. Your program will likely be tested with DIFFERENT data.)


1楼2015-11-05 14:41回复