#include int main(void) { char line[10001]; char* now; int last; int h; int c; int repeatlefts; while(gets(line)!=NULL) { c = 0; /*printf("%s", line);*/ now = line; while(*now!='\0') now++; last=-1; repeatlefts = 0; while(now>=line) { switch (*now) { case 'i': h = 1; break; case 'v': h = 5; break; case 'x': h = 10; break; case 'l': h = 50; break; case 'c': h = 100; break; case 'd': h = 500; break; case 'm': h = 1000; break; default: h = 0; } if (h) { if (lasth) { /* ignore */ } else if (last==h) { if (repeatlefts) { c += h; if (repeatlefts>0) repeatlefts--; } } last = h; } now--; } printf("%d\n", c); } return 0; }