#21121: 求救!! 我到底哪裡錯了QAQ


peterlin910502@gmail.com (林彥緻)

學校 : 不指定學校
編號 : 116246
來源 : [49.216.161.118]
最後登入時間 :
2020-04-14 20:55:28
a013. 羅馬數字 -- NPSC 模擬試題 | From: [49.216.161.118] | 發表日期 : 2020-04-14 21:10

#include <iostream>

#include <string>

 

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

 

using namespace std;

 

int main(int argc, char** argv) {

int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0;

string str1="",str2="";

while(cin >> str1 >> str2) {

for(a=0;a<20;a++) {

if(str1[a]=='C' and str1[a+1]=='M') {

b=b+900;

a=a+1;

}

else if(str1[a]=='C' and str1[a+1]=='D') {

b=b+400;

a=a+1;

}

else if(str1[a]=='X' and str1[a+1]=='C') {

b=b+90;

a=a+1;

}

else if(str1[a]=='X' and str1[a+1]=='L') {

b=b+40;

a=a+1;

}

else if(str1[a]=='I' and str1[a+1]=='X') {

b=b+9;

a=a+1;

}

else if(str1[a]=='I' and str1[a+1]=='V') {

b=b+4;

a=a+1;

}

else if(str1[a]=='M') {

b=b+1000;

}

else if(str1[a]=='D') {

b=b+500;

}

else if(str1[a]=='C') {

b=b+100;

}

else if(str1[a]=='L') {

b=b+50;

}

else if(str1[a]=='X') {

b=b+10;

}

else if(str1[a]=='V') {

b=b+5;

}

else if(str1[a]=='I') {

b=b+1;

}

}

for(a=0;a<20;a++) {

if(str2[a]=='C' and str2[a+1]=='M') {

c=c+900;

a=a+1;

}

else if(str2[a]=='C' and str2[a+1]=='D') {

c=c+400;

a=a+1;

}

else if(str2[a]=='X' and str2[a+1]=='C') {

c=c+90;

a=a+1;

}

else if(str2[a]=='X' and str2[a+1]=='L') {

c=c+40;

a=a+1;

}

else if(str2[a]=='I' and str2[a+1]=='X') {

c=c+9;

a=a+1;

}

else if(str2[a]=='I' and str2[a+1]=='V') {

c=c+4;

a=a+1;

}

else if(str2[a]=='M') {

c=c+1000;

}

else if(str2[a]=='D') {

c=c+500;

}

else if(str2[a]=='C') {

c=c+100;

}

else if(str2[a]=='L') {

c=c+50;

}

else if(str2[a]=='X') {

c=c+10;

}

else if(str2[a]=='V') {

c=c+5;

}

else if(str2[a]=='I') {

c=c+1;

}

}

if(b>c) {

d=b-c;

}

if(b<c) {

d=c-b;

}

if (b==c) {

cout << "ZERO";

}

else {

e=d/1000;

for(a=0;a<e;a++) {

cout << "M";

}

f=d/100-10*e;

if(f==9) {

cout << "CM";

}

else if(f==4) {

cout << "CD";

}

else if(f>=5) {

cout << "D";

for(a=0;a<f-5;a++) {

cout << "C";

}

}

else {

for(a=0;a<f;a++) {

cout << "C";

}

}

g=d/10-10*f-100*e;

if(g==9) {

cout << "XC";

}

else if(g==4) {

cout << "XL";

}

else if(g>=5) {

cout << "L";

for(a=0;a<g-5;a++) {

cout << "X";

}

}

else {

for(a=0;a<g;a++) {

cout << "X";

}

}

h=d%10;

if(h==9) {

cout << "IX";

}

else if(h==4) {

cout << "IV";

}

else if(h>=5) {

cout << "V";

for(a=0;a<h-5;a++) {

cout << "I";

}

}

else {

for(a=0;a<h;a++) {

cout << "I";

}

}

}

cout << endl;

b=c=d=e=f=g=h=0;

}

return 0;

}

 
ZeroJudge Forum