refer to "One-day-one-leetcode"
In the previous blog we discussed the conversion of numbers within 1~3999 to Roman numerals, highlighting some of the expressions of non-7 standard Roman numerals, such as 4,6,3 and so on, which we talked about converting Roman numerals into integer numbers.
In fact, we are in the conversion of the main attention to 4,40,400, such as the number of expression can be.
Code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int tonum (char ch);
int Romantoint (string s) {
int ret = 0;
int i = 0;
while (I < s.length ()) {
if (i + 1 < s.length () && tonum (s[i)) < Tonum (s[i + 1])) {
ret = Tonum (s [i + 1]) -Tonum (S[i]);
i++;
}
else{
ret + tonum (s[i]);
}
i++;
}
return ret;
}
int tonum (char ch) {
int num = 0;
Switch (CH) {case
' I ': num = 1;
Case ' V ': num = 5; break;
Case ' X ': num = 10; break;
Case ' L ': num = 50; break;
Case ' C ': num = 100; break;
Case ' D ': num = 500; break;
Case ' M ': num = 1000; break;
return num;
}
int main () {
string s = ' mmmdcclxxii ';
int con = Romantoint (s);
cout << con << endl;
return 0;
}
Run Result: