2th integer_to_roman

来源:互联网 发布:csgo网络不稳定 编辑:程序博客网 时间:2024/06/05 21:52
#include <iostream>#include <string>#include <cstring>//std::string strroman[]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};class Solution {public:    std::string intToRoman(int num) {int i;std::string roman;int value[]={1000,900,500,400,100,90,50,40,10,9,5,4,1};    std::string Roman[ ]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};//char roman[20];    for ( i = 0; num > 0; ++i) {       int count;   count = num/value[i];       num %= value[i];       for (; count > 0; --count)     {    roman +=  Roman[i];}    } return roman;   }};int main(){   using namespace std;   int Integer;   //string roman;   cout <<  "Integer: ";   Solution integer_to_roman;   cin >> Integer ;   cout<< "Roman:"<<integer_to_roman.intToRoman(Integer)<<endl;   system("pause");   return 0;}