数字发音
来源:互联网 发布:淘宝mac版 编辑:程序博客网 时间:2024/04/28 23:55
- 有一个非负整数,请编写一个算法,打印该整数的英文描述。
给定一个int x,请返回一个string,为该整数的英文描述。 - 测试样例: 1234 返回:”One Thousand,Two Hundred Thirty Four”
private string[] belowTen = new String[] {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"}; private string[] belowTwenty = new String[] {"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"}; private string[] belowHundred = new String[] {"", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}; public string toString(int x){ if (x == 0) return "Zero"; return helper(x); } private String helper(int num) { string result = ""; if (num < 10) result = belowTen[num]; else if (num < 20) result = belowTwenty[num - 10]; else if (num < 100) result = belowHundred[num / 10] + " " + helper(num % 10); else if (num < 1000) result = helper(num / 100) + " Hundred " + helper(num % 100); else if (num < 1000000) result = helper(num / 1000) + " Thousand" +( num % 1000 > 0 ? "," : " ") + helper(num % 1000); else if (num < 1000000000) result = helper(num / 1000000) + " Million" + (num % 1000000 > 0 ? "," : " ") + helper(num % 1000000); else result = helper(num / 1000000000) + " Billion " + helper(num % 1000000000); return result.Trim(' ');}
0 0
- 数字发音
- 数字发音
- 数字发音
- 关于数字0的发音
- 面试题: 数字转英文 数字发音
- 《Cracking the Coding Interview程序员面试金典》----数字发音
- SQL发音
- 希腊字母发音
- 发音校正
- 术语发音
- 中英文发音
- 希腊语发音
- 英语发音
- C#发音
- 日语发音
- 罗马字母发音
- 韩语发音
- 鼻音发音
- 设计模式——适配器模式(Adapter)
- 关于unity里pbr技术和材质 unity5默认shader和传统的对比
- 【腾讯TMQ】漫步VR——Unity语音聊天室开发小结
- hdu 2110 Crisis of HDU
- “一盘沙拉”带你入门Dagger2(三)之@Qualifier
- 数字发音
- Spring Batch 之 skip讲解(九)
- Android真机测试安装时报错Installation error: INSTALL_FAILED_DEXOPT
- unity再战PBR材质流程与材质制作实践
- jQuery 核心 - noConflict() 方法
- SpringMVC加载WebApplicationContext源码分析
- Android开发之广播
- Java中使用Jedis操作Redis
- JQUERY AJAX上传文件