東京大学 情報理工学系研究科 創造情報学専攻 2015年8月実施 プログラミング
Author
Description (English)
Write programs for the following questions. When writing the programs, you must not use a built-in library function that directly implements the specified behavior. For example, the program for (1) must not include a call to to_i in Ruby.
(1) Write a program that reads a number in the quaternary representation (base-4 positional notation) and prints it in the decimal representation. For example, it reads 123 and prints 27.
(2) Suppose that symbols a, b, c, ..., h denote numbers 0, 1, 2, ..., 7, respectively. Write a program that reads a number expressed with a, b, c, ..., h in the octal representation and prints the number in the decimal representation. For example, it reads bcd and prints 83.
(3) Write on the answer sheet decimal number 2015 in Roman numerals.
Roman numerals use seven symbols I, V, X, L, C, D, and M. Their values are 1, 5, 10, 50, 100, 500, and 1000, respectively. They are formed as follows:
Numbers are formed by combining symbols and adding the values. So II is two ones, i.e. XIII is a ten and three ones, i.e. CCVII, using the symbols for two hundreds, a five and two ones. MLXVI, one thousand, fifty and ten, a five and a one.
Symbols are placed from left to right in order of value, starting with the largest. However, in a few specific cases, to avoid four characters being repeated in succession (such as IIII or XXXX) these can be reduced using subtractive notation as follows:
- the numeral I can be placed before V and X to make
units ( IV) andunits ( IX) respectively - X can be placed before L and C to make
( XL) and( XC) respectively - C can be placed before D and M to make
( CD) and( CM)
An example using the above rules would be MCMIV.
(Reference: http://en.wikipedia.org/wiki/Roman_numerals)
The symbols have to be selected so that the number of the symbols will be the minimum. For example, IV is composed of two symbols.
(4) Write a program that reads a number in Roman numerals and prints it in the decimal representation. Assume that the number is more than
(5) Write a program that reads a number in the decimal representation and prints it in Roman numerals. The number is more than
(6) Extend the subtraction notation of Roman numerals as follows.
A symbol can be placed between adjacent larger symbols
and than that symbol, where or is blank. For example, CIL is because . IL is because .
Write a program that reads a number in the decimal representation and prints it in the extended Roman numerals. The number is more than
(7) Write a program that reads a number expressed in English and prints it in the decimal representation. The number is a positive integer less than
fifty four thousand three hundred twelve
and prints 54312. The program may accept at least one English expression for each number. For example, for one thousand two hundred or twelve hundred.