Meine recht kurze C++-Variante: Unterstützt auch IV, IX, XL, etc
Code:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
if(argc < 2) {
cout << "Usage: a.out <arabische Zahl>" << endl;
return -1;
}
int zahl = atoi(argv[1]);
string rom[] = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
int romval[] = {1,4,5,9,10,40,50,90,100,400,500,900,1000};
for(int i=(sizeof(rom)/sizeof(rom[0])); i>=0; i--) {
while((zahl-=romval[i])>0)
cout << rom[i];
if(zahl < 0)
zahl += romval[i];
if(zahl == 0)
{cout << rom[i]; cout << endl; return 0;}
}
} ./a.out 1439