zoukankan      html  css  js  c++  java
  • Integer to Roman

    Given an integer, convert it to a roman numeral.

    Input is guaranteed to be within the range from 1 to 3999.

    class Solution {
    public:
        string intToRoman(int num) {
            int mp[100];
            int val[]={1000,900,500,400,100,90,50,40,10,9,5,4,1};
            string r[]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
            mp['I']=1;
            mp['V']=5;
            mp['X']=10;
            mp['L']=50;
            mp['C']=100;
            mp['D']=500;
            mp['M']=1000;
            
            int index=0;
            string result="";
            while(num>0)
            {
                while(num<val[index])
                    index++;
                result=result+r[index];
                num=num-val[index];
            }
            return result;
        }
    }; 
  • 相关阅读:
    软件体系结构课后作业03
    Struts2初步认识
    springboot1
    pytorch安装
    classifier of chains
    python错误集锦
    svm-惩罚因子
    毕设笔记1----div样式
    SQLite
    MVC实例应用模式
  • 原文地址:https://www.cnblogs.com/erictanghu/p/3759231.html
Copyright © 2011-2022 走看看