Leetcode:integer to Roman

Source: Internet
Author: User

Integer to Roman


Total Accepted: 64703 Total Submissions: 165064 Difficulty: Medium

Given an integer, convert it to a Roman numeral.

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

Subscribe to see which companies asked this question

Hide TagsMath StringHide Similar Problems(E) Roman to Integer (H)-Integer to 中文版 Words














C + + code:

Class Solution {public:    string inttoroman (int num) {        string m[] = {"", "M", "MM", "MMM"};        String c[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};        String x[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};        String i[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};        return m[num/1000] + c[(num%1000)/100] + x[(num%100)/10] + i[num%10];    }};


Leetcode:integer to Roman

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.