# 思路
使用map儲存各符號的值
將符號的值加總,若當前符號大於前一個符號,則代表相減
# 參考程式碼
static auto fast_io = []
{
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
return 0;
}();
class Solution {
public:
int romanToInt(string s)
{
int ret = 0;
char tmp = 'M';
unordered_map<char, int> dict = <!--swig0-->;
for (auto& c : s)
{
ret += dict[c];
if (dict[tmp] < dict[c]) ret -= dict[tmp] * 2;
tmp = c;
}
return ret;
}
};