제목 설명
정수를 감안할 때, 로마 숫자로 변환합니다. 입력이 1 내지 3999의 범위에 있도록한다.
사고
첫째, 문자열의 디지털 변환, 하나 개의 프로세스 하나, 함수 호출 캔 도움말
코드
class Solution {
public:
string Help(string s, int i, int len)
{
string record = "IVXLCDMT";
string res;
int number = s[i] - '0';
if (number>0)
{
int a = number / 5;
int b = number % 5;
if (b == 4)
{
res += record[(len - i) * 2 - 2];
res += record[(len - i) * 2 - 1 + a];
}
else
{
if (a == 1)
res += record[(len - i) * 2 - 1];
while (b > 0)
{
res += record[(len - i) * 2 - 2];
b--;
}
}
}
return res;
}
string intToRoman(int num) {
string res;
string s = to_string(num);
int len = s.length();
for (int i = 0; i< len; i++)
{
res += Help(s, i, len);
}
return res;
}
};