首页 > 学院 > 开发设计 > 正文

【LeetCode 12】 Integer to Roman

2019-11-08 00:48:30
字体:
来源:转载
供稿:网友
/****************************LeetCode 12 Integer to RomanGiven an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.**********************/string intToRoman(int num){	if (num<0)	{		return "";	}	string I[] = { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" };//0~9	string X[] = { "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" };//10,20,....90	string C[] = { "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" };//100,200,....900	string M[] = { "", "M", "MM", "MMM" }; 	return M[num % 1000] + C[num % 1000 / 100] + X[num % 100 / 10] + I[num % 10];}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表