code連結 http://ideone.com/W6QVoM
請問一下問題出在哪裡??
ideone測試都正常
但是在測資2 出現WA
#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");
break;
}
else{
for(count = cal/100;count>0;count--){
cal = (cal - 100*count);
if(count == 9){
printf("CM");
break;
}
if(count == 4){
printf("CD");
break;
}
if(count>=5){
printf("D");
count = count-5;
}
printf("D");
}
for(count = cal/10;count>0;count--){
cal = (cal - 10*count);
if(count == 9){
printf("XC");
break;
}
if(count == 4){
printf("XL");
break;
}
if(count>=5){
printf("L");
count = count-5;
}
printf("X");
}
for(count = cal/1;count>0;count--){
cal = (cal - count);
if(count == 9){
printf("IX");
break;
}
if(count == 4){
printf("IV");
break;
}
if(count>=5){
printf("V");
count = count-5;
}
printf("I");
}
}
printf("\n");
}
return 0;
}