Roman To Number | Strings | C++ Solution
Roman To Number, is a Strings related problem and in this post we will see how we can solve this challenge in C++
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999. Example :
Input : "XIV" Return : 14 Input : "XX" Output : 20 If a character with smaller value lie before one with a larger value then the smaller character is subtracted from the immediate next bigger valued character
so for current character check if value(curr) < value (curr + 1): value = value - value(curr) else value += value(curr) give the values of the Roman Numerals for storing the value of the Roman Numerals for each character check its next character if the priority of next character is lesser than subtract value if current priority is greater than or equal to the next then add value
Please check the main.cpp snippet for the solution.
This solution originally posted at: Github by @susantabiswas