Cody

Problem 63. Encode Roman Numerals

Solution 2640223

Submitted on 1 Jul 2020 by 春樹 内糸
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
x = 1990; y_correct = 'MCMXC'; assert(isequal(dec2rom(x),y_correct))

n = 990 romStr = 'M' n = 90 romStr = 'MCM' n = 0 romStr = 'MCMXC'

2   Pass
x = 2008; y_correct = 'MMVIII'; assert(isequal(dec2rom(x),y_correct))

n = 1008 romStr = 'M' n = 8 romStr = 'MM' n = 3 romStr = 'MMV' n = 2 romStr = 'MMVI' n = 1 romStr = 'MMVII' n = 0 romStr = 'MMVIII'

3   Pass
x = 1666; y_correct = 'MDCLXVI'; assert(isequal(dec2rom(x),y_correct))

n = 666 romStr = 'M' n = 166 romStr = 'MD' n = 66 romStr = 'MDC' n = 16 romStr = 'MDCL' n = 6 romStr = 'MDCLX' n = 1 romStr = 'MDCLXV' n = 0 romStr = 'MDCLXVI'

4   Pass
x = 49; y_correct = 'XLIX'; assert(isequal(dec2rom(x),y_correct))

n = 9 romStr = 'XL' n = 0 romStr = 'XLIX'

5   Pass
x = 45; y_correct = 'XLV'; assert(isequal(dec2rom(x),y_correct))

n = 5 romStr = 'XL' n = 0 romStr = 'XLV'

6   Pass
x = 0; y_correct = ''; assert(isempty(dec2rom(x)))

Suggested Problems

More from this Author95

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!