#include #include #include #include using namespace std; int getI(char c){ switch (c) { case 'i' : return 0; case 'v' : return 1; case 'x' : return 2; case 'l' : return 3; case 'c' : return 4; case 'd' : return 5; case 'm' : return 6; } return -1; } int getNum(int i){ switch (i){ case 0 : return 1; case 1 : return 5; case 2 : return 10; case 3 : return 50; case 4 : return 100; case 5 : return 500; case 6 : return 1000; } return 0; } long read (char ch){ stack sstack; while(ch!='\n' && ch!=EOF){ if (ch=='i' || ch=='v' || ch=='x' || ch=='l' || ch=='c' || ch=='d' || ch=='m') sstack.push(ch); ch = cin.get(); } int count[7]={0,0,0,0,0,0,0}; bool found[7]={false,false,false,false,false,false,false}; while(!sstack.empty()){ ch = sstack.top(); int i=getI(ch); if ((i>=0) && (!found[i])){ for (int j=0;j=0;i--) { if (i%2==0 && count[i]>3) count[i]=3; if (i%2==1 && count[i]>1) count[i]=1; final+=count[i]*getNum(i); } return final; } int main (void){ char c; while ((c=cin.get()) != EOF){ cout << read(c) << endl; } return 0; }