#include #include #include int parser(char *vst) { int ret=0, i=0, poz = 0, poc = 0; /*M*/ while (vst[i] != '\0') { if (vst[i] == 'm') { ret += 1000; poz = i; } i++; } i = poz; while (vst[i] != '\0') { if (vst[i] == 'd') { ret += 500; poz = i; break; } i++; } i = poz; poc = 0; while ((vst[i] != '\0') && (poc < 3)) { if (vst[i] == 'c') { ret += 100; poz = i; poc ++; } i++; } i = poz; poc = 0; while (vst[i] != '\0') { if (vst[i] == 'l') { ret += 50; poz = i; break; } i++; } i = poz; poc = 0; while ((vst[i] != '\0') && (poc < 3)) { if (vst[i] == 'x') { ret += 10; poz = i; poc ++; } i++; } i = poz; poc = 0; while (vst[i] != '\0') { if (vst[i] == 'v') { ret += 5; poz = i; break; } i++; } i = poz; poc = 0; while ((vst[i] != '\0') && (poc < 3)) { if (vst[i] == 'i') { ret += 1; poz = i; poc ++; } i++; } return ret; while (vst[i] != '\0') { /* if(vst[i] == 'I' && vst[i+1] == 'V') { ret += 4; i += 2; } if(vst[i] == 'I' && vst[i+1] == 'X') { ret += 9; i += 2; continue; } if(vst[i] == 'I' && vst[i+1] == 'X') { ret += 9; i += 2; continue; } if(vst[i] == 'X' && vst[i+1] == 'L') { ret += 40; i += 2; continue; }if(vst[i] == 'X' && vst[i+1] == 'C') { ret += 90; i += 2; continue; }if(vst[i] == 'C' && vst[i+1] == 'D') { ret += 400; i += 2; continue; } if(vst[i] == 'C' && vst[i+1] == 'M') { ret += 900; i += 2; continue; } */ if(vst[i] == 'I') { ret += 1; i += 1; continue; } if(vst[i] == 'V') { ret += 5; i += 1; continue; } if(vst[i] == 'X') { ret += 10; i += 1; continue; } if(vst[i] == 'L') { ret += 50; i += 1; continue; } if(vst[i] == 'M') { ret += 1000; i += 1; continue; } if(vst[i] == 'D') { ret += 500; i += 1; continue; } if(vst[i] == 'C') { ret += 100; i += 1; continue; } } return ret; } int main(void) { char *vst; vst = (char *) malloc (10000); while ((gets(vst)) != NULL) { printf("%d\n",parser (vst)); } return 0; }