#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
char num1[100],num2[100];
while(scanf("%s %s%*c",num1,num2) != EOF){
int n1=0,n2=0,n3=0,i=0,j=0;
for(i = 0; i < strlen(num1); i++){
if(num1[i] == 'C' && num1[i+1] == 'M'){
n1+=900;
i+=1;
}
else if(num1[i] == 'C' && num1[i+1] == 'D'){
n1+=400;
i+=1;
}
else if(num1[i] == 'X' && num1[i+1] == 'C'){
n1 += 90;
i+=1;
}
else if(num1[i] == 'X' && num1[i+1] == 'L'){
n1+=40;
i+=1;
}
else if(num1[i] == 'I' && num1[i+1] == 'V'){
n1+=4;
i+=1;
}
else if(num1[i] == 'I' && num1[i+1] == 'X'){
n1+=9;
i+=1;
}
else if(num1[i] =='I')
n1+=1;
else if(num1[i] =='V')
n1+=5;
else if(num1[i] =='X')
n1+=10;
else if(num1[i] =='L')
n1+=50;
else if(num1[i] =='C')
n1+=100;
else if(num1[i] =='D')
n1+=500;
else if(num1[i] =='M')
n1+=1000;
}
for(i = 0; i < strlen(num2); i++){
if(num2[i] == 'C' && num2[i+1] == 'M'){
n2+=900;
i+=1;
}
else if(num2[i] == 'C' && num2[i+1] == 'D'){
n2+=400;
i+=1;
}
else if(num2[i] == 'X' && num2[i+1] == 'C'){
n2+=90;
i+=1;
}
else if(num2[i] == 'X' && num2[i+1] == 'L'){
n2+=40;
i+=1;
}
else if(num2[i] == 'I' && num2[i+1] == 'V'){
n2+=4;
i+=1;
}
else if(num2[i] == 'I' && num2[i+1] == 'X'){
n2+=9;
i+=1;
}
else if(num2[i] =='I')
n2+=1;
else if(num2[i] =='V')
n2+=5;
else if(num2[i] =='X')
n2+=10;
else if(num2[i] =='L')
n2+=50;
else if(num2[i] =='C')
n2+=100;
else if(num2[i] =='D')
n2+=500;
else if(num2[i] =='M')
n2+=1000;
}
n3 = n1 - n2;
if(n3<0)
n3 *= -1;
if(n3 == 0)
printf("ZERO\n");
if((n3/1000) > 0 )
for(j = n3/1000;j>=1;j--)
printf("M");
n3 %= 1000;
if(n3 >= 900){
printf("CM");
n3 -= 900;
}
if(n3 >= 400 && n3 < 500){
printf("CD");
n3 -= 400;
}
if(n3/500 > 0 )
for(j = n3/500;j>=1;j--)
printf("D");
n3 %= 500;
if(n3/100 > 0 )
for(j = n3/100;j>=1;j--)
printf("C");
n3 %= 100;
if(n3 >= 90){
printf("XC");
n3 -= 90;
}
if(n3>=40 && n3 <50){
printf("XL");
n3 -= 40;
}
if(n3/50 > 0 )
for(j = n3/50;j>=1;j--)
printf("L");
n3 %= 50;
if(n3/10 > 0 )
for(j = n3/10;j>=1;j--)
printf("X");
n3 %= 10;
if (n3 == 0)
printf("\n");
if(n3 == 9)
printf("IX\n");
else if(n3 == 4)
printf("IV\n");
else if(n3 == 5)
printf("V\n");
else if(n3 == 1)
printf("I\n");
else if(n3 == 2)
printf("II\n");
else if(n3 == 3)
printf("III\n");
else if(n3 == 6)
printf("VI\n");
else if(n3 == 7)
printf("VII\n");
else if(n3 == 8)
printf("VIII\n");
}
return 0;
}
找了好久還是不知道為什麼錯,求各位大大解釋><