Question: C++ Roman Numerals Create a function that takes in a Roman numeral as a string and converts it to an integer, returning the result. The
C++
Roman Numerals
Create a function that takes in a Roman numeral as a string and converts it to an integer, returning the result. The function should work for all Roman numerals representing positive integers less than 4000
readRomanNumbers("VII") 7 readRomanNumbers("DCLXXIX") 679 readRomanNumbers("MMMCMV") 3905Examples
Notes
-
All letters will be in uppercase.
-
Assume all inputs will be well-formed Roman numerals.
-
While you could probably solve this by separately checking for each of these
sequences inside the string, there is a smarter way. Think about the numerical value each individual letter has, and how the letter immediately following it can affect that letter's numerical value.
int readRomanNumbers(std::string num) { }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
