#include<iostream> #include<vector> #include<string> using namespace std; int main() { int num; cin>>num; string result; int a1[]={1000,900,500,400,100,90,50,40,10,9,5,4,1}; string a2[]={"M", "CM", "D", "CD", "C", "XC","L", "XL", "X", "IX", "V", "IV", "I"}; int i=0; while(num>0) { int count=num/a1[i]; while(count--) result+=a2[i]; num=num%a1[i]; i++; } cout<<result<<endl; }
时间: 2024-11-02 23:36:43