#20330: 與測試不符


walker19576@gmail.com (L0u15)

學校 : 臺北市私立薇閣高級中學
編號 : 96112
來源 : [111.235.252.27]
最後登入時間 :
2023-06-05 13:50:25
a013. 羅馬數字 -- NPSC 模擬試題 | From: [210.243.39.11] | 發表日期 : 2020-01-03 13:09

在exe黨策士沒錯但用zerojudge測試執行就錯了

#include<iostream>
#include<map>
using namespace std;

int main()
{
map<char,int> roman;
roman['I']=1;
roman['V']=5;
roman['X']=10;
roman['L']=50;
roman['C']=100;
roman['D']=500;
roman['M']=1000;
string one,two;
long int first,second,ans;
cin>>one;
while(cin>>two){
first=0;
second=0;
for(int i=0;i<one.length();++i)
first+=roman[one[i]];
for(int i=0;i<two.size();++i)
second+=roman[two[i]];
for(int i=1;i<one.size();++i)
if(roman[one[i]]>roman[one[i-1]])
first-=roman[one[i-1]]*2;
for(int i=1;i<two.size();++i)
if(roman[two[i]]>roman[two[i-1]])
second-=roman[two[i-1]]*2;
ans=first-second;
if(ans<0)
ans=-ans;
else if(ans==0){
cout<<"ZERO\n";
continue;
}
while(ans>=1000){
cout<<"M";
ans-=1000;
}
if(ans>=900){
cout<<"CM";
ans-=900;
}
else if(ans>=500){
cout<<"D";
ans-=500;
}
while(ans>=100){
cout<<"C";
ans-=100;
}
if(ans>=90){
cout<<"XC";
ans-=90;
}
else if(ans>=50){
cout<<"L";
ans-=50;
}
while(ans>=10){
cout<<"X";
ans-=10;
}
if(ans>=9){
cout<<"IX";
ans-=9;
}
else if(ans>=5){
cout<<"V";
ans-=5;
}
while(ans>=1){
cout<<"I";
ans-=1;
}
cout<<"\n";
cin>>one;
if(one=="#")
break;
}
return 0;
}

 
ZeroJudge Forum