about | help | code help+videos | done | prefs |
Given an input parameter 'num', return its Roman Numeral equivalent if 'num' is a positive integer value in the range 1<=num<=3999. If 'num' is outside that range, return "failed to convert". For this problem, you must use the more modern interpretation of Roman Numerals such that the symbols used could add or subtract from the total. The symbols should appear in strictly decreasing order of value, unless they are used to indicate subtraction. For example, the number 4 would be represented as "IV" NOT as "IIII". The number 999 would be represented as "CMXCIX". No other order is correct. For THIS problem, the subtraction aspect is only applicable for the NEXT symbol in order. For example, "CM" means 900, but "XM" does NOT mean 990 (10 less than 1000) because the X was not the next symbol in order of decreasing value. You can ONLY use the subtraction based on the NEXT symbol in decreasing order of value. Note that this subtraction scheme is NOT used if there is an easier way to represent the number. For example, both "DM" and "D" mean 500, but "D" is an easier way to represent 500, so "DM" is NEVER used. The same is true of "LC" and "VX". This scheme basically is only applicable to the following combinations: "CM" means 900; "CD" means 400; "XC" means 90; "XL" means 40; "IX" means 9; and "IV" means 4. Various symbols and their values are given below. You may assume that these are the only symbols to be used in the string (with the exception of the "fail to convert" message). I 1 V 5 X 10 L 50 C 100 D 500 M 1000 You might consider using helper methods (although I didn't). Look at the test data for examples. test2021_11_04_BONUS_unMinus(15) → "XV" test2021_11_04_BONUS_unMinus(999) → "CMXCIX" test2021_11_04_BONUS_unMinus(1) → "I" ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 320
Copyright Nick Parlante 2017 - privacy