刷题记忆
#include <iostream>
#include <string>
#include <cstring>
class Solution {
public:
int RomanToInt(std::string str){
int length = str.size();
int sum =0;
int i;
for(i=0;i<length;i++)
{
sum+=Roman_To_Int(str[i]);
}
// system("pause");
return sum;
}
int Roman_To_Int(char c)
{
switch (c)
{
case 'I':
return 1;
case 'V':
return 5;
case 'X':
return 10;
case 'L':
return 50;
case 'C':
return 100;
case 'D':
return 500;
case 'M':
return 1000;
default:
return 0;
}
}
};
int main()
{
using namespace std;
string roman;
cout << "Roman: ";
Solution roman_to_integer;
getline(cin,roman);
cout<< "Integer:"<<roman_to_integer.RomanToInt(roman)<<endl;
system("pause");
return 0;
}