4928: 捕捉缬草

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:4 通过:3

题目描述

C. Capture Valerian
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.
Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captured by Shapur and Shapur is now going to capture Valerian, the Roman emperor.
Being defeated, the cowardly Valerian hid in a room at the top of one of his castles. To capture him, Shapur has to open many doors. Fortunately Valerian was too scared to make impenetrable locks for the doors.
Each door has 4 parts. The first part is an integer number a. The second part is either an integer number b or some really odd sign which looks like R. The third one is an integer c and the fourth part is empty! As if it was laid for writing something. Being extremely gifted, after opening the first few doors, Shapur found out the secret behind the locks.
c is an integer written in base a, to open the door we should write it in base b. The only bad news is that this R is some sort of special numbering system that is used only in Roman empire, so opening the doors is not just a piece of cake!
Here's an explanation of this really weird number system that even doesn't have zero:
Roman numerals are based on seven symbols: a stroke (identified with the letter I) for a unit, a chevron (identified with the letter V) for a five, a cross-stroke (identified with the letter X) for a ten, a C (identified as an abbreviation of Centum) for a hundred, etc.:
  • I=1
  • V=5
  • X=10
  • L=50
  • C=100
  • D=500
  • M=1000
Symbols are iterated to produce multiples of the decimal (1, 10, 100, 1,000) values, with V, L, D substituted for a multiple of five, and the iteration continuing: I 1, II 2, III 3, V 5, VI 6, VII 7, etc., and the same for other bases: X 10, XX 20, XXX 30, L 50, LXXX 80; CC 200, DCC 700, etc. At the fourth and ninth iteration, a subtractive principle must be employed, with the base placed before the higher base: IV 4, IX 9, XL 40, XC 90, CD 400, CM 900.
Also in bases greater than 10 we use A for 10, B for 11, etc.
Help Shapur capture Valerian and bring peace back to Persia, especially Armenia.
Input
The first line contains two integers a and b (2≤a,b≤25). Only b may be replaced by an R which indicates Roman numbering system.
The next line contains a single non-negative integer c in base a which may contain leading zeros but its length doesn't exceed 103.
It is guaranteed that if we have Roman numerals included the number would be less than or equal to 300010 and it won't be 0. In any other case the number won't be greater than 101510.


Output
Write a single line that contains integer c in base b. You must omit leading zeros.


就是公元260,沙普尔非常聪明,成为波斯国王。他现在被称为沙普尔,伊朗和阿尼兰的万王之王陛下。

最近,罗马人向波斯宣战。他们梦想占领亚美尼亚。在最近的战争中,罗马人被严重击败。现在他们的高级陆军将领菲利普被沙普尔俘虏,沙普尔现在要俘虏罗马皇帝瓦勒里安。

被击败后,懦弱的瓦莱里安躲在他的一座城堡顶部的一个房间里。为了抓住他,沙普尔必须打开许多门。幸运的是,缬草太害怕了,没有为门做坚不可摧的锁。

每扇门都有4部件。第一部分是数字a.第二部分是整数b或者一些非常奇怪的标志,看起来像R。第三个是整数c第四部分是空的!好像是为了写什么而准备的。沙普尔天赋异禀,在打开前几扇门后,发现了锁背后的秘密。

c是用基数写的整数a,要打开门,我们应该把它写在基地b.唯一的坏消息是,这个R是某种仅在罗马帝国使用的特殊编号系统,所以打开门不仅仅是小菜一碟!

以下是对这个甚至没有零的非常奇怪的数字系统的解释:

罗马数字基于七个符号:笔画(用字母 I 标识)表示单位,V 形(用字母 V 标识)表示五,十字笔画(用字母 X 标识)表示十,C(标识为 Centum 的缩写)表示一百,等等:

  • I=1
  • V=5
  • X=10
  • L=50
  • C=100
  • D=500
  • M=1000

迭代符号以生成小数点 (1,10,100,1000) 值,其中 V、L、D 替换为 5 的倍数,迭代继续: I 1 , II 2 , III 3 , V 5 , VI 6 , VII 7 , 等等, 其他进制也一样: X 10 , XX 20 , XXX 30 , L 50 , LXXX 80 ; CC 200 , DCC 700 , 等等. 在第四次和第九次迭代中,必须采用减法原则,将底放在更高的进制之前: IV 4 , IX 9 , XL 40 , XC 90 , CD 400 , CM 900 .

也有进制大于 10 我们用 A 代表10 , B 代表 11 , 等等.



帮助沙普尔占领缬草,将和平带回波斯,尤其是亚美尼亚。




Examples
Input
10 2
1
Output
1
Input
16 R
5
Output
V
Input
5 R
4
Output
IV
Input
2 2
1111001
Output
1111001
Input
12 13
A
Output
A
Note
You can find more information about roman numerals here: http://en.wikipedia.org/wiki/Roman_numerals

输入样例 复制


输出样例 复制


分类标签