![](/style/img/answer_avatar.png)
#include <iostream>
#include <string>
using namespace std;
string solve(int num, int divd)
{
string result = "";
int count = 0;
while(num)
{
count = num / divd;
if(count)
{
num %= divd;
for (int i = 0; i < count; i++)
switch(divd)
{
case 1000:
{
result+="M";
break;
}
case 900:
{
result+="CM";
break;
}
case 800:
{
result+="DCC";
break;
}
case 700:
{
result+="DCC";
break;
}
case 600:
{
result+="DC";
break;
}
case 500:
{
result+="D";
break;
}
case 400:
{
result+="CD";
break;
}
case 300:
{
result+="CCC";
break;
}
case 200:
{
result+="CC";
break;
}
case 100:
{
result+="C";
break;
}
case 90:
{
result+="XC";
break;
}
case 80:
{
result+="LXXX";
break;
}
case 70:
{
result+="LXX";
break;
}
case 60:
{
result+="LX";
break;
}
case 50:
{
result+="L";
break;
}
case 40:
{
result+="XL";
break;
}
case 30:
{
result+="XXX";
break;
}
case 20:
{
result+="XX";
break;
}
case 10:
{
result+="X";
break;
}
case 9:
{
result+="IX";
break;
}
case 8:
{
result+="VIII";
break;
}
case 7:
{
result+="VII";
break;
}
case 6:
{
result+="VI";
break;
}
case 5:
{
result+="V";
break;
}
case 4:
{
result+="IV";
break;
}
case 3:
{
result+="III";
break;
}
case 2:
{
result+="II";
break;
}
case 1:
{
result+="I";
break;
}
}
}
if(divd <= 1000 && divd > 100) divd-=100;
else if(divd <= 100 && divd > 10) divd-=10;
else divd-=1;
}
return result;
}
int main()
{
int num,count;
cin >> num;
if(num <= 3999) cout << solve(num,1000);
else cout << "Incorrect input.";
return 0;
}
#include <string>
using namespace std;
string solve(int num, int divd)
{
string result = "";
int count = 0;
while(num)
{
count = num / divd;
if(count)
{
num %= divd;
for (int i = 0; i < count; i++)
switch(divd)
{
case 1000:
{
result+="M";
break;
}
case 900:
{
result+="CM";
break;
}
case 800:
{
result+="DCC";
break;
}
case 700:
{
result+="DCC";
break;
}
case 600:
{
result+="DC";
break;
}
case 500:
{
result+="D";
break;
}
case 400:
{
result+="CD";
break;
}
case 300:
{
result+="CCC";
break;
}
case 200:
{
result+="CC";
break;
}
case 100:
{
result+="C";
break;
}
case 90:
{
result+="XC";
break;
}
case 80:
{
result+="LXXX";
break;
}
case 70:
{
result+="LXX";
break;
}
case 60:
{
result+="LX";
break;
}
case 50:
{
result+="L";
break;
}
case 40:
{
result+="XL";
break;
}
case 30:
{
result+="XXX";
break;
}
case 20:
{
result+="XX";
break;
}
case 10:
{
result+="X";
break;
}
case 9:
{
result+="IX";
break;
}
case 8:
{
result+="VIII";
break;
}
case 7:
{
result+="VII";
break;
}
case 6:
{
result+="VI";
break;
}
case 5:
{
result+="V";
break;
}
case 4:
{
result+="IV";
break;
}
case 3:
{
result+="III";
break;
}
case 2:
{
result+="II";
break;
}
case 1:
{
result+="I";
break;
}
}
}
if(divd <= 1000 && divd > 100) divd-=100;
else if(divd <= 100 && divd > 10) divd-=10;
else divd-=1;
}
return result;
}
int main()
{
int num,count;
cin >> num;
if(num <= 3999) cout << solve(num,1000);
else cout << "Incorrect input.";
return 0;
}
0
0