/************************************************************************
* Project:ACM
* Function:a013
*************************************************************************
*
*************************************************************************
*
* Create time:2016-10-23-15.51
* Last edit time:now
*
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef enum { false, true } bool;
int RDlist[1002];
void Dec2Rom(int dec_int) { //convert and print;
char dec_str[10];
sprintf(dec_str,"%d",dec_int);
int i;
for(i=0;i<strlen(dec_str);i++){
printRom(dec_str[i]-'0',strlen(dec_str)-i);
}
}
void printRom(int num,int digit) { // done EX: 30 num=3 digit=2
int i;int dig2ten=1;
for(i=1;i<digit;i++){
dig2ten*=10;
}
int one =RDlist[1*dig2ten];
int five=RDlist[5*dig2ten];
int ten =RDlist[10*dig2ten];
switch(num) {
case 1:
printf("%c",one);
break;
case 2:
printf("%c%c",one,one);
break;
case 3:
printf("%c%c%c",one,one,one);
break;
case 4:
printf("%c%c",one,five);
break ;
case 5:
printf("%c",five);
break;
case 6:
printf("%c%c",five,one);
break;
case 7:
printf("%c%c%c",five,one,one);
break;
case 8:
printf("%c%c%c%c",five,one,one,one);
break;
case 9:
printf("%c%c",one,ten);
break;
}
}
int Rom2Dec(char *rom_str) { // done
int dec_int=0;
int ri;
for(ri=0; ri<strlen(rom_str); ri++) {
if(RDlist[rom_str[ri]]>=RDlist[rom_str[ri+1]])
dec_int+=RDlist[rom_str[ri]];
else
dec_int-=RDlist[rom_str[ri]];
}
return dec_int;
}
void setRDlist() { // done
RDlist[1]='I';
RDlist[5]='V';
RDlist[10]='X';
RDlist[50]='L';
RDlist[100]='C';
RDlist[500]='D';
RDlist[1000]='M';
RDlist['I']=1;
RDlist['V']=5;
RDlist['X']=10;
RDlist['L']=50;
RDlist['C']=100;
RDlist['D']=500;
RDlist['M']=1000;
}
void a013(void) {
char s1[10],s2[10];
setRDlist();
while( scanf("%s",s1)!=EOF ) {
if(localBreak(s1))break;
scanf("%s",s2);
int ronum1,ronum2;
ronum1 = Rom2Dec(s1);
ronum2 = Rom2Dec(s2);
if(ronum1==ronum2)printf("ZERO");
else Dec2Rom(ronum1-ronum2);
printf("\n");
}
}
int localBreak(char *str) {
#ifdef LOCAL
if(!strcmp(str,"#"))return true;
#endif // LOCAL
return false;
}
#ifndef LOCAL
int main() {
a013();
return 0;
}
#endif //LOCAL