code 連結: http://ideone.com/LhDT7I
在ideone跟網站測試MM III都出現正解
但是把答案送出後
在測資7 出現 我的答案是MMCCXVII
而不是MCMXCVII 不知到問題出在哪
#include <stdio.h>
int main(void) {
int one;
int two;
int count =0;
char s[100];
char j[100];
int cal;
int i = 0;
while(scanf("%s %s",s,j)==2){
one = 0;
two = 0;
while(s[i++]!='\0'){
switch(s[i-1]){
case 'I' :
one = one + 1;
break;
case 'V' :
one = one + 5;
break;
case 'X' :
one = one + 10;
break;
case 'L' :
one = one +50;
break;
case 'C' :
one = one +100;
break;
case 'D' :
one = one +500;
break;
case 'M' :
one = one +1000;
break;
}
}
i = 0;
while(j[i++]!='\0'){
switch(j[i-1]){
case 'I' :
one = one - 1;
break;
case 'V' :
one = one - 5;
break;
case 'X' :
one = one - 10;
break;
case 'L' :
one = one -50;
break;
case 'C' :
one = one -100;
break;
case 'D' :
one = one -500;
break;
case 'M' :
one = one -1000;
break;
}
}
i = 0;
int cal = abs(one);
if(cal == 0){
printf("ZERO\n");
}
else{
for(count = cal/1000; count>0;count--){
cal = cal - 1000;
printf("M");
}
for(count = cal/100;count>0;count--){
if(count == 9){
printf("CM");
cal = (cal - 100*count);
break;
}
if(count == 4){
printf("CD");
cal = (cal - 100*count);
break;
}
if(count>=5){
printf("D");
cal = (cal - 500);
count = count-5;
}
if(count>0){
printf("C");
cal = (cal - 100);
}
}
for(count = cal/10;count>0;count--){
if(count == 9){
printf("XC");
cal = (cal - 10*count);
break;
}
if(count == 4){
printf("XL");
cal = (cal - 10*count);
break;
}
if(count>=5){
printf("L");
cal = (cal - 50);
count = count-5;
}
if(count>0){
printf("X");
cal = cal -10 ;
}
}
for(count = cal/1;count>0;count--){
cal = (cal - count);
if(count == 9){
printf("IX");
cal = (cal - count);
break;
}
if(count == 4){
printf("IV");
cal = (cal - count);
break;
}
if(count>=5){
printf("V");
cal = (cal - 5);
count = count-5;
}
if(count>0){
printf("I");
cal = (cal - 1);
}
}
}
printf("\n");
}
return 0;
}