1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
int digit, thousand, hundred, ten, one;
string Numeral;
const char* _THOUSANDS[] = {"", "M", "MM", "MMM"};
const char* _HUNDREDS[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
const char* _TENS[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
const char* _ONES[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
cout << "Please enter a number: ";
cin >> digit;
if (digit <= 3999)
{
thousand = digit / 1000;
digit = digit % 1000;
hundred = digit % 100;
ten = digit / 10;
one = digit % 10;
Numeral = _THOUSANDS[thousand] + _HUNDREDS[hundred] + _TENS[ten] + _ONES[one];
cout << Numeral;
system("pause");
}
}
| |