#12410: C語言 測資2 WA 共輸出1行


james0452000 (Falcon)

學校 : 國立陽明大學
編號 : 67452
來源 : [120.126.109.217]
最後登入時間 :
2017-09-04 20:30:39
a013. 羅馬數字 -- NPSC 模擬試題 | From: [120.126.109.217] | 發表日期 : 2017-07-22 01:13

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;
}

 

 
#12411: Re:C語言 測資2 WA 共輸出1行


anandrewboy70900 (ShowTsai)

學校 : 國立中央大學
編號 : 27736
來源 : [203.204.218.144]
最後登入時間 :
2024-10-11 16:21:37
a013. 羅馬數字 -- NPSC 模擬試題 | From: [140.115.204.235] | 發表日期 : 2017-07-22 02:11

 

print完zero 不用break




 
ZeroJudge Forum