数字的英文表达(趣味题C#)
来源:互联网 发布:矩阵相乘值的性质 编辑:程序博客网 时间:2024/04/29 01:56
趣味题
输入一个正整数N(N最大是4位数),输出它的英文表达
class Program { static void Main(string[] args) { var table = aa(); print(table, 1024); Console.WriteLine(); print(table, 135); Console.WriteLine(); print(table, 29); Console.WriteLine(); print(table, 10); Console.WriteLine(); print(table, 8); } static Dictionary<int, string> aa() { Dictionary<int, string> table = new Dictionary<int, string>(29); table.Add(0, "zero"); table.Add(1, "one"); table.Add(2, "two"); table.Add(3, "three"); table.Add(4, "four"); table.Add(5, "five"); table.Add(6, "six"); table.Add(7, "seven"); table.Add(8, "eight"); table.Add(9, "nine"); table.Add(10, "ten"); table.Add(11, "eleven"); table.Add(12, "twelve"); table.Add(13, "thirteen"); table.Add(14, "fourteen"); table.Add(15, "fifteen"); table.Add(16, "sixteen"); table.Add(17, "seventeen"); table.Add(18, "eighteen"); table.Add(19, "ninteen"); table.Add(20, "twenty"); table.Add(30, "thirty"); table.Add(40, "forty"); table.Add(50, "fifty"); table.Add(60, "sixty"); table.Add(70, "seventy"); table.Add(80, "eighty"); table.Add(90, "ninty"); table.Add(100, "hundred"); table.Add(1000, "thousand"); return table; } //输入一个正整数N(N最大是4位数),输出它的英文表达 static void print(Dictionary<int, string> table, int n) { if (n >= 0 && n <= 19) { Console.Write(table[n]); //直接输出19以内的数字 } else if (n >= 20 && n <= 99 && n % 10 == 0) //整十 { Console.Write(table[n / 10 * 10]); } else if (n >= 20 && n <= 99) //先输出十位,再输出个位 { Console.Write(table[n / 10 * 10] + " " + table[n % 10]); } else if (n >= 100 && n <= 999) { print(table, n / 100); Console.Write(" " + table[100] + " "); //输出百位 print(table, n % 100); //递归调用,输出十位和个位 } else if (n >= 1000 && n <= 999999) { print(table, n / 1000); Console.Write(" " + table[1000] + " "); //输出千位 print(table, n % 1000); //递归调用,输出百位、十位和个位 } } }
0 0
- 数字的英文表达(趣味题C#)
- 其他题目---数字的英文表达和中文表达
- python:将数字转换成用英文表达的程序
- 标点符号的英文表达
- 常用符号的英文表达
- 中国小吃的英文表达
- 各种“假日”的英文表达
- “剩女”的英文表达
- 工作单位的英文表达
- 数学符号的英文表达
- 编程的标点 英文表达
- 数学冷知识:不断取英文表达的字符数,最后总会得到数字4
- 表达数字的英文字母计数
- 数学运算符号的英文表达
- 中国各级行政区划的英文表达
- 嵌入式--一些单词的英文表达
- 趣味题 c语言
- 立此存照(16)[C++]如何将一个数字转换为英文读法--英文三位计数法的英文转换
- 实验一 NPC问题——回溯算法、聚类分析
- STM32F103C8T6 短路
- android获取屏幕坐标点
- [C/C++标准库]_[初级]_[字符串string转换大小写]
- Javascript的简单数据类型
- 数字的英文表达(趣味题C#)
- Hadoop Pipes程序运行报错Server failed to authenticate解决方法
- Android之内存泄漏调试学习与总结
- android 4.0.3最新源码下载编译
- ExtJS国际化
- ubuntu 未知显示器 unkown display 问题解决
- MFC数据的传递
- GitHub Android 开源项目汇总
- memcached搭建缓存系统