#include <iostream>
#include <algorithm>
#include "string"
#include "vector"
using namespace std;
int romanToInt(string s)
{
int num = 0,pirror = 0;
for (int i = 1; i < s.length(); i++)
{
int temp = num;
switch (s[i])
{
case 'I':num += 1; break;
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;
}
/*if (s[i] > pirror)
{
num=-num;
}*/
if (num - temp > pirror)
{
num = num - 2 * pirror;
}
pirror = num - temp;
}
return num;
}
int main()
{
cout << romanToInt("IV");
system("pause");
return 0;
}