This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| int romanToInt(string s) { | |
| int i = 0; int result = 0; | |
| enum r {I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000}; | |
| while(i < s.length()) | |
| { | |
| switch(s[i]) | |
| { | |
| case 'M': result += M; break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public: | |
| string intToRoman(int num) { | |
| string result = ""; | |
| int numerals[7] = { 1, 5, 10, 50, 100, 500, 1000 }; | |
| char numerals_key[7] = { 'I', 'V', 'X', 'L', 'C', 'D', 'M'}; | |
| int remainders[6] = { 4, 9, 40, 90, 400, 900 }; | |
| char* remainders_key[6] = { "IV", "IX", "XL", "XC", "CD", "CM"}; |