#include <iostream>
#include <unordered_map>
#include <string>
int romanToInt(const std::string& s) {
std::unordered_map<char, int> romanValues = {
{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50},
{'C', 100}, {'D', 500}, {'M', 1000}
};
int total = 0;
int prevValue = 0;
for (char ch : s) {
int currentValue = romanValues[ch];
if (currentValue > prevValue) {
total += currentValue - 2 * prevValue;
} else {
total += currentValue;
}
prevValue = currentValue;
}
return total;
}
int main() {
std::string roman = "XCVII";
std::cout << "The integer value of " << roman << " is " << romanToInt(roman) << std::endl;
}
/*
run:
The integer value of XCVII is 97
*/