LeetCode #12 Integer to Roman C# Solution
2016-05-05 15:39
465 查看
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
最开始的我还是太天真了。我甚至以为罗马符号只有X,V,I
我还是图simple啊……
“M”,”CM”,”D”,”CD”,”C”,”XC”,”L”,”XL”,”X”,”IX”,”V”,”IV”,”I”
1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1
我的心好痛。
Input is guaranteed to be within the range from 1 to 3999.
最开始的我还是太天真了。我甚至以为罗马符号只有X,V,I
我还是图simple啊……
“M”,”CM”,”D”,”CD”,”C”,”XC”,”L”,”XL”,”X”,”IX”,”V”,”IV”,”I”
1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1
我的心好痛。
C# Code public class Solution { public string IntToRoman(int num) { string[] ch = new string[] { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" }; int[] value = new int[] { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; string ans = ""; for (int i=0;num!=0;++i) { while (num >= value[i]) { num -= value[i]; ans += ch[i]; } } return ans; } }
相关文章推荐
- C#静态代码检查工具StyleCode -- 自定义规则
- C#静态代码检查工具StyleCode -- 规则解析
- LeetCode #11 Container With Most Water C# Solution
- C#静态代码检查工具StyleCode -- 初探
- C#资深开发组 427769854
- .Net中C#的DllImport的用法
- [C#脚本]-荒岛逃生游戏制作
- c# 读写自定义配置文件
- c#的static什么时候使用
- C# Process.Start()
- C#中fixed关键字的作用总结
- c# 读写配置信息
- C# Timer用法及实例讲解
- c# 中 EventHandler<TEventArgs>的 异步调用
- 转载:《.NET 编程结构》专题汇总(C#)
- C#中的@符号
- 重温C#2.0之委托(delegate,Delegate,MulticastDelegate)与事件(event)区别
- c#多线程通信之委托(事件)
- C#中小数点后保留两位小数,四舍五入的函数及使用方法
- MarshalAs的使用