#include <iostream> #include <conio.h> #include <locale.h> using namespace std; #define NVALS 13 void main() { setlocale(LC_CTYPE,"Russian"); cout << "Введите исходное число (1..1999) арабскими цифрами:"; int n; cin >> n; if(n<1||n>1999) { cout << "Неверно введено число"; return; } unsigned int vals[NVALS]={1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000}; char* roms[NVALS]={"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"}; int b=NVALS-1; int j=0; char res[10]={0}; while(n) { while(vals[b]>n)b--; res[j] = *roms[b]; j++; if (b%2 == 1) { res[j] = *(roms[b]+1); j++; } n-=vals[b]; } cout << res; _getch(); } |