include <stdio.h> #include <stdlib.h> #include <string.h> int rta(char r[]){ int num[15],sum=0; memset(num,'\0',15); for(int i=0;r[i]!='\0';i++){ switch(r[i]){ case 73: num[i]=1; break; case 86: num[i]=5; break; case 88: num[i]=10; break; case 76: num[i]=50; break; case 67: num[i]=100; break; case 68: num[i]=500; break; case 77: num[i]=1000; break; } } for(int i=0;num[i]!='\0';i++){ if(num[i+1]){ sum+=num[i]<num[i+1]?num[i]*-1:num[i]; }else{ sum+=num[i]; } } return sum; } void atr(int a){ int sol[4]; int j=1000,n=a; char s[15]; memset(s,'\0',15); for(int i=0;i<4;i++){ sol[i]=n/j; n%=j; j/=10; } for(int i=0;i<sol[0];i++){ printf("M"); } switch(sol[1]){ case 1: case 2: case 3: for(int i=0;i<sol[1];i++){ printf("C"); } break; case 4: printf("D"); break; case 5: case 6: case 7: case 8: printf("D"); for(int i=0;i<sol[1]-5;i++){ printf("C"); } break; case 9: printf("CM"); } switch(sol[2]){ case 1: case 2: case 3: for(int i=0;i<sol[2];i++){ printf("X"); } break; case 4: printf("XL"); break; case 5: case 6: case 7: case 8: printf("L"); for(int i=0;i<sol[2]-5;i++){ printf("X"); } break; case 9: printf("XC"); } switch(sol[3]){ case 1: case 2: case 3: for(int i=0;i<sol[3];i++){ printf("I"); } break; case 4: printf("IV"); break; case 5: case 6: case 7: case 8: printf("V"); for(int i=0;i<sol[3]-5;i++){ printf("I"); } break; case 9: printf("IX"); } printf("\n"); } int main(){ char a[15],b[15]; int x,y,ans; while(1){ scanf("%s",a); if(*a=='#'){ break; } scanf("%s",b); x=rta(a); y=rta(b); ans=abs(x-y); if(ans==0){ printf("ZERO\n"); }else{ atr(ans); } } return 0; }