#20670: 幫忙看一下哪裡錯(自己測ok,但傳上去有問題)


angusben (adamben)

學校 : 私立辭修高級中學
編號 : 109521
來源 : [36.226.203.21]
最後登入時間 :
2024-01-18 10:25:17
a013. 羅馬數字 -- NPSC 模擬試題 | From: [111.71.72.217] | 發表日期 : 2020-02-18 12:06

#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
int sum;
int rom_num(string x){
sum=0;
for(int i=0;i<x.size();i++){
if(x[i]=='I')
sum=sum+1;
else if(x[i]=='V')
sum=sum+5;
else if(x[i]=='X')
sum=sum+10;
else if(x[i]=='L')
sum=sum+50;
else if(x[i]=='C')
sum=sum+100;
else if(x[i]=='D')
sum=sum+500;
else
sum=sum+1000;
}
return sum;
}
void num_rom(int x){
while(x!=0){
if(x>=1000){
cout<<"M";
x=x-1000;
}
else if(x>=900){
cout<<"CM";
x=x-900;
}
else if(x>=500){
cout<<"D";
x=x-500;
}
else if(x>=400){
cout<<"CD";
x=x-400;
}
else if(x>=100){
cout<<"C";
x=x-100;
}
else if(x>=90){
cout<<"XC";
x=x-90;
}
else if(x>=50){
cout<<"L";
x=x-50;
}
else if(x>=40){
cout<<"XL";
x=x-40;
}
else if(x>=10){
cout<<"X";
x=x-10;
}
else if(x>=9){
cout<<"IX";
x=x-9;
}
else if(x>=5){
cout<<"V";
x=x-5;
}
else if(x>=4){
cout<<"IV";
x=x-4;
}
else{
cout<<"I";
x=x-1;
}
}
cout<<endl;

}
int main(){
int fin;
string a,b;
while(cin>>a&&a[0]!='#'){
cin>>b;
fin= abs(rom_num(a)-rom_num(b));
if(fin==0)
cout<<"ZERO"<<endl;
else
num_rom(fin);
}
}

 

 
#20742: Re:幫忙看一下哪裡錯(自己測ok,但傳上去有問題)


felixhuang07@gmail.com (Yay!)

學校 : 不指定學校
編號 : 114853
來源 : [114.44.2.67]
最後登入時間 :
2021-02-16 22:33:39
a013. 羅馬數字 -- NPSC 模擬試題 | From: [175.96.88.249] | 發表日期 : 2020-02-28 15:35

#include
#include
#include
using namespace std;
int sum;
int rom_num(string x){
sum=0;
for(int i=0;i<x.size();i++){
if(x[i]=='I')
sum=sum+1;
else if(x[i]=='V')
sum=sum+5;
else if(x[i]=='X')
sum=sum+10;
else if(x[i]=='L')
sum=sum+50;
else if(x[i]=='C')
sum=sum+100;
else if(x[i]=='D')
sum=sum+500;
else
sum=sum+1000;
}
return sum;
}
void num_rom(int x){
while(x!=0){
if(x>=1000){
cout<<"M";
x=x-1000;
}
else if(x>=900){
cout<<"CM";
x=x-900;
}
else if(x>=500){
cout<<"D";
x=x-500;
}
else if(x>=400){
cout<<"CD";
x=x-400;
}
else if(x>=100){
cout<<"C";
x=x-100;
}
else if(x>=90){
cout<<"XC";
x=x-90;
}
else if(x>=50){
cout<<"L";
x=x-50;
}
else if(x>=40){
cout<<"XL";
x=x-40;
}
else if(x>=10){
cout<<"X";
x=x-10;
}
else if(x>=9){
cout<<"IX";
x=x-9;
}
else if(x>=5){
cout<<"V";
x=x-5;
}
else if(x>=4){
cout<<"IV";
x=x-4;
}
else{
cout<<"I";
x=x-1;
}
}
cout<<endl;

}
int main(){
int fin;
string a,b;
while(cin>>a&&a[0]!='#'){
cin>>b;
fin= abs(rom_num(a)-rom_num(b));
if(fin==0)
cout<<"ZERO"<<endl;
else
num_rom(fin);
}
}

 

 

我的也不行QQ



 
ZeroJudge Forum