#include<stdio.h>#include<string.h>
int main(){int inputa=0;int inputb=0;int value=0;
while(1){inputa=0;inputb=0;int numarr[4]={0};char word={0};char word0={'A'};while(1){scanf("%c",&word);if(word==32){break;}else if(word=='#'){return 0;}if(word=='I'){inputa++;}else if(word=='V'){inputa+=5;if(word0=='I'){inputa-=2;}}else if(word=='X'){inputa+=10;if(word0=='I'){inputa-=2;}}else if(word=='L'){inputa+=50;if(word0=='X'){inputa-=20;}}else if(word=='C'){inputa+=100;if(word0=='X'){inputa-=20;}}else if(word=='D'){inputa+=500;if(word0=='C'){inputa-=200;}}else if(word=='M'){inputa+=1000;if(word0=='C'){inputa-=200;}}word0=word;}//printf("%d\n",inputa);
while(1){scanf("%c",&word);if(word==10){break;}if(word=='I'){inputb++;}else if(word=='V'){inputb+=5;if(word0=='I'){inputb-=2;}}else if(word=='X'){inputb+=10;if(word0=='I'){inputb-=2;}}else if(word=='L'){inputb+=50;if(word0=='X'){inputb-=20;}}else if(word=='C'){inputb+=100;if(word0=='X'){inputb-=20;}}else if(word=='D'){inputb+=500;if(word0=='C'){inputb-=200;}}else if(word=='M'){inputb+=1000;if(word0=='C'){inputb-=200;}}word0=word;}//printf("-%d\n",inputb);value=inputa-inputb;if(value<0){value*=-1;}else if(value==0){printf("ZERO");}
for(int i=3;i>=0;i--){numarr[i]=value%10;value/=10;//printf("r");}while(numarr[0]>=1){printf("M");numarr[0]-=1;}if(numarr[1]==9){printf("CM");}else{if(numarr[1]>=5&&numarr[1]<=8){printf("D");numarr[1]-=5;}while(numarr[1]>=1){printf("C");numarr[1]-=1;}}if(numarr[2]==9){printf("XC");}else{if(numarr[2]>=5&&numarr[2]<=8){printf("L");numarr[2]-=5;}while(numarr[2]>=1){printf("X");numarr[2]-=1;}}if(numarr[3]==9){printf("IX");}else{if(numarr[3]>=5&&numarr[3]<=8){printf("V");numarr[3]-=5;}while(numarr[3]>=1){printf("I");numarr[3]-=1;}}printf("\n");}}
輸入第二個羅馬數字前把word0改掉