2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: a7f4d8f2483413a6ce226cac
|
2020-12-16 00:37:30 -07:00
|
|
|
title: 罗马数字转换器
|
2018-10-10 18:03:03 -04:00
|
|
|
challengeType: 5
|
2020-09-07 16:17:22 +08:00
|
|
|
forumTopicId: 16044
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --description--
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
把传入的数字转为罗马数字。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
转换后的[罗马数字](http://www.mathsisfun.com/roman-numerals.html)字母必须都是大写。
|
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(2)` 应返回 "II"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(2), 'II');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(3)` 应返回 "III"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(3), 'III');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(4)` 应返回 "IV"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(4), 'IV');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(5)` 应返回 "V"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(5), 'V');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(9)` 应返回 "IX"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(9), 'IX');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(12)` 应返回 "XII"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(12), 'XII');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(16)` 应返回 "XVI"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(16), 'XVI');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(29)` 应返回 "XXIX"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(29), 'XXIX');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(44)` 应返回 "XLIV"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(44), 'XLIV');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(45)` 应返回 "XLV"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(45), 'XLV');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(68)` 应返回 "LXVIII"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(68), 'LXVIII');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(83)` 应返回 "LXXXIII"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(83), 'LXXXIII');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(97)` 应返回 "XCVII"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(97), 'XCVII');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(99)` 应返回 "XCIX"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(99), 'XCIX');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(400)` 应返回 "CD"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(400), 'CD');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(500)` 应返回 "D"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(500), 'D');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(501)` 应返回 "DI"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(501), 'DI');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(649)` 应返回 "DCXLIX"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(649), 'DCXLIX');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(798)` 应返回 "DCCXCVIII"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(798), 'DCCXCVIII');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(891)` 应返回 "DCCCXCI"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(891), 'DCCCXCI');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(1000)` 应返回 "M"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(1000), 'M');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(1004)` 应返回 "MIV"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(1004), 'MIV');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(1006)` 应返回 "MVI"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(1006), 'MVI');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(1023)` 应返回 "MXXIII"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(1023), 'MXXIII');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(2014)` 应返回 "MMXIV"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(2014), 'MMXIV');
|
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`convertToRoman(3999)` 应返回 "MMMCMXCIX"。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert.deepEqual(convertToRoman(3999), 'MMMCMXCIX');
|
|
|
|
```
|
|
|
|
|
|
|
|
# --solutions--
|
|
|
|
|