#28266: RE能不能幫我看一下哪裡有問題?測試都正常

#### u010731@tcivs.tc.edu.tw (超級不會寫程式)

School : No School
ID : 162766
2022-01-11 19:52:24
a013. 羅馬數字 -- | From: [219.100.37.246] | Post Date : 2021-11-23 15:10

#include <iostream>
#include<string>
using namespace std;
string Rome,Rome_a,Rome_b;
int Jump_out = 1,number,number_a,number_b,X;

int main() {
while(Jump_out == 1)
{
Rome_a.clear();
Rome_b.clear();
Rome.clear();
X = 0 ;
while(cin >> Rome_a)
{
if(Rome_a == "#")
{
Jump_out = 0;
break;
}
else
{
number_a = 0;
for(int i = 0;i < Rome_a.length();i++)
{
if(Rome_a[i] == 'I' && Rome_a[i+1] == 'V')
{
number_a += 4;
i += 1;
}
else if(Rome_a[i] == 'I' && Rome_a[i+1] == 'X')
{
number_a += 9;
i += 1;
}
else if(Rome_a[i] == 'X' && Rome_a[i+1] == 'L')
{
number_a += 40;
i += 1;
}
else if(Rome_a[i] == 'X' && Rome_a[i+1] == 'C')
{
number_a += 90;
i += 1;
}
else if(Rome_a[i] == 'C' && Rome_a[i+1] == 'D')
{
number_a += 400;
i += 1;
}
else if(Rome_a[i] == 'C' && Rome_a[i+1] == 'M')
{
number_a += 900;
i += 1;
}
else
{
switch(Rome_a[i])
{
case 'I': number_a += 1;
break;
case 'V': number_a += 5;
break;
case 'X': number_a += 10;
break;
case 'L': number_a += 50;
break;
case 'C': number_a += 100;
break;
case 'D': number_a += 500;
break;
case 'M': number_a += 1000;
break;
}
}
}
}
break;
}
if (Jump_out == 1)
{
while(cin >> Rome_b)
{
number_b = 0;
for(int i = 0;i < Rome_b.length();i++)
{
if(Rome_b[i] == 'I' && Rome_b[i+1] == 'V')
{
number_b += 4;
i += 1;
}
else if(Rome_b[i] == 'I' && Rome_b[i+1] == 'X')
{
number_b += 9;
i += 1;
}
else if(Rome_b[i] == 'X' && Rome_b[i+1] == 'L')
{
number_b += 40;
i += 1;
}
else if(Rome_b[i] == 'X' && Rome_b[i+1] == 'C')
{
number_b += 90;
i += 1;
}
else if(Rome_b[i] == 'C' && Rome_b[i+1] == 'D')
{
number_b += 400;
i += 1;
}
else if(Rome_b[i] == 'C' && Rome_b[i+1] == 'M')
{
number_b += 900;
i += 1;
}
else
{
switch(Rome_b[i])
{
case 'I': number_b += 1;
break;
case 'V': number_b += 5;
break;
case 'X': number_b += 10;
break;
case 'L': number_b += 50;
break;
case 'C': number_b += 100;
break;
case 'D': number_b += 500;
break;
case 'M': number_b += 1000;
break;
}
}
}
break;
}
number = number_a - number_b;
if (number == 0)
{
cout << "ZERO" << endl;
}
else
{
while(number != 0)
{
if (number >= 1000)
{
Rome[X] = 'M';
number -= 1000;
}
else if (number >= 500)
{
if (number >= 900)
{
Rome[X] = 'C';
Rome[X+1] = 'M';
number -= 900;
X += 1;
}
else
{
Rome[X] = 'D';
number -= 500;
}
}
else if (number >= 100)
{
if (number >= 400)
{
Rome[X] = 'C';
Rome[X+1] = 'D';
number -= 400;
X += 1;
}
else
{
Rome[X] = 'C';
number -= 100;
}
}
else if (number >= 50)
{
if (number >= 90)
{
Rome[X] = 'X';
Rome[X+1] = 'C';
number -= 90;
X += 1;
}
else
{
Rome[X] = 'L';
number -= 50;
}
}
else if (number >= 10)
{
if (number >= 40)
{
Rome[X] = 'X';
Rome[X+1] = 'L';
number -= 40;
X += 1;
}
else
{
Rome[X] = 'X';
number -= 10;
}
}
else if (number >= 5)
{
if (number == 9)
{
Rome[X] = 'I';
Rome[X+1] = 'X';
number -= 9;
X += 1;
}
else
{
Rome[X] = 'V';
number -= 5;
}
}
else
{
if (number == 4)
{
Rome[X] = 'I';
Rome[X+1] = 'V';
number -= 4;
X += 1;
}
else
{
Rome[X] = 'I';
number -= 1;
}
}
X += 1;
}
for (int i = 0;i < X;i++)
{
cout << Rome[i];
}
cout << endl;
}
}
}
}

#28270: Re:RE能不能幫我看一下哪裡有問題?測試都正常

#### cges30901 (cges30901)

School : No School
ID : 30877
2022-01-26 20:07:05
a013. 羅馬數字 -- | From: [39.9.43.177] | Post Date : 2021-11-23 19:35

number = number_a - number_b;

（另外你把string當成陣列這種用法我覺得很奇怪，雖然剛好可以AC，但我會用Rome+=這樣子寫比較簡單）

#28859: Re:RE能不能幫我看一下哪裡有問題?測試都正常

#### u010731@tcivs.tc.edu.tw (超級不會寫程式)

School : No School
ID : 162766
2022-01-11 19:52:24
a013. 羅馬數字 -- | From: [111.83.103.159] | Post Date : 2022-01-08 12:33

number = number_a - number_b;

（另外你把string當成陣列這種用法我覺得很奇怪，雖然剛好可以AC，但我會用Rome+=這樣子寫比較簡單）

ZeroJudge Forum