我的程式碼為什麼CD會判斷為DC呢
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
int b=0,bc=0,i,ii,sum=1,myAbs[100],time=0,ftime;
char a[100]={""};
char c[100];
while(a[0]!='#')
{
scanf("%s",a);
b=0;bc=0;
if(a[0]=='#')
break;
else
{
scanf("%s",c);
for(i=0;i<strlen(a);i++)
{
switch (a[i])
{
case 'I':
b+=1;
break;
case 'V':
if(a[i-1]=='I')
b+=3;
else
b+=5;
break;
case 'X':
if(a[i-1]=='I')
b+=8;
else
b+=10;
break;
case 'L':
if(a[i-1]=='X')
b+=30;
else
b+=50;
break;
case 'C':
if(a[i-1]=='X')
b+=80;
else
b+=100;
break;
case 'D':
if(a[i-1]=='C')
b+=300;
else
b+=500;
break;
case 'M':
if(a[i-1]=='C')
b+=800;
else
b+=1000;
break;
}
}
for(i=0;i<strlen(c);i++)
{
switch (c[i])
{
case 'I':
bc+=1;
break;
case 'V':
if(c[i-1]=='I')
{
bc+=3;
}
else
bc+=5;
break;
case 'X':
if(c[i-1]=='I')
bc+=8;
else
bc+=10;
break;
case 'L':
if(c[i-1]=='X')
bc+=30;
else
bc+=50;
break;
case 'C':
if(c[i-1]=='X')
bc+=80;
else
bc+=100;
break;
case 'D':
if(c[i-1]=='C')
bc+=300;
else
bc+=500;
break;
case 'M':
if(a[i-1]=='C')
bc+=800;
else
bc+=1000;
break;
}
}
myAbs[time]=abs(b-bc);
time++;
ftime=time;
}
}
time=0;
while(time<ftime)
{
if(myAbs[time]==0)
{
printf("ZERO\n");
time++;
}
else if(myAbs[time]>=1000)
{
myAbs[time]-=1000;
if(myAbs[time]==0)
{
printf("M\n");
time++;
}
else
{
printf("M");
}
}
else if(myAbs[time]>=900)
{
myAbs[time]-=900;
if(myAbs[time]==0)
{
printf("CM\n");
time++;
}
else
{
printf("CM");
}
}
else if(myAbs[time]>=500 && myAbs[time]<900)
{
i=myAbs[time]/100;
myAbs[time]-=(myAbs[time]/100)*100;
printf("D");
for(i;i>5;i--)
{
printf("C");
}
if(myAbs[time]==0)
{
printf("\n");
time++;
}
}
else if(myAbs[time]>=400 && myAbs[time]<500)
{
myAbs[time]-=400;
if(myAbs[time]==0)
{
printf("CD\n");
time++;
}
else
{
printf("CD");
}
}
else if(myAbs[time]<400 && myAbs[time]>=100)
{
i=myAbs[time]/100;
myAbs[time]-=(myAbs[time]/100)*100;
for(i;i>0;i--)
{
printf("C");
}
if(myAbs[time]==0)
{
printf("\n");
time++;
}
}
else if(myAbs[time]<=99 && myAbs[time]>=90)
{
myAbs[time]-=90;
if(myAbs[time]==0)
{
printf("XC\n");
time++;
}
else
{
printf("XC");
}
}
else if(myAbs[time]<=89 && myAbs[time]>=50)
{
i=myAbs[time]/10;
myAbs[time]-=(myAbs[time]/10)*10;
printf("L");
for(i;i>5;i--)
{
printf("X");
}
if(myAbs[time]==0)
{
printf("\n");
time++;
}
}
else if(myAbs[time]<=49 && myAbs[time]>=40)
{
myAbs[time]-=40;
if(myAbs[time]==0)
{
printf("XL\n");
time++;
}
else
{
printf("XL");
}
}
else if(myAbs[time]<=39 && myAbs[time]>=10)
{
i=myAbs[time]/10;
myAbs[time]-=(myAbs[time]/10)*10;
for(i;i>=1;i--)
{
printf("X");
}
if(myAbs[time]==0)
{
printf("\n");
time++;
}
}
else if(myAbs[time]==9)
{
printf("IX\n");
time++;
}
else if(myAbs[time]<=8 && myAbs[time]>=5)
{
printf("V");
i=myAbs[time];
for(i;i>5;i--)
{
printf("I");
}
time++;
printf("\n");
}
else if(myAbs[time]==4)
{
printf("IV\n");
time++;
}
else if(myAbs[time]>=1 && myAbs[time]<=3)
{
i=myAbs[time];
for(i;i>0;i--)
{
printf("I");
}
time++;
printf("\n");
}
}
return 0;
}