C#编写程序将数字转换成英文:如32:thirty two ,123:one hundred and twenty three.说明:1、输入文件格式为input.txt,输出文件格式为output.txt;2、数字为正整数,长度不超过十位,不考虑小数,转化结果为

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/11 15:22:44

C#编写程序将数字转换成英文:如32:thirty two ,123:one hundred and twenty three.说明:1、输入文件格式为input.txt,输出文件格式为output.txt;2、数字为正整数,长度不超过十位,不考虑小数,转化结果为
C#编写程序将数字转换成英文:如32:thirty two ,123:one hundred and twenty three.
说明:
1、输入文件格式为input.txt,输出文件格式为output.txt;
2、数字为正整数,长度不超过十位,不考虑小数,转化结果为英文小写 ;
3、输出格式为100=one hundred (参考out.txt );
4、非法数据请返回“error”,不存在空行;
5、关键词提示:billion ,million,thousand ,hundred .
ps:
input.txt的文本信息为:
0
01
10
11
99
100
101
199
999
1001
9999
10000
100000
100001
1000000
10000000
100000001
1020300401
102a300401
是个体
output文件
0=zero
01=one
10=ten
11=eleven
99=ninety nine
100=one hundred
101=one hundred and one
199=one hundred and ninety nine
999=nine hundred and ninety nine
1001=one thousand one
9999=nine thousand nine hundred and ninety nine
10000=ten thousand
100000=one hundred thousand
100001=one hundred thousand one
1000000=one million
10000000=ten million
100000001=one hundred million one
1020300401=one billion twenty million three hundred thousand four hundred and one
102a300401=error
是个体=error

C#编写程序将数字转换成英文:如32:thirty two ,123:one hundred and twenty three.说明:1、输入文件格式为input.txt,输出文件格式为output.txt;2、数字为正整数,长度不超过十位,不考虑小数,转化结果为
static void Main(string[] args)
        {
            string readFilePath = AppDomain.CurrentDomain.BaseDirectory + "input.txt";
            List<string> list = ReadFile(readFilePath);
            
            //写文件,将每一行写入文件中
            string writeFilePath = AppDomain.CurrentDomain.BaseDirectory + "output.txt";
            FileStream fs = new FileStream(writeFilePath, FileMode.Create, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("gb2312"));
            int number;
            for (int i = 0; i < list.Count; i++)
            {
                string output = "";
                if (int.TryParse(list[i], out number) == false)
                {
                    output = "error";
                }
                else 
                {
                    output = NumberToEnglishString(number);
                }
                sw.WriteLine("{0}={1}", list[i], output);
            }
            sw.Close();
            fs.Close();
            //程序结束后在debug文件夹下会生成output.txt
            Console.ReadLine();            
        }
        /// <summary>
        /// 读取文件 将每一行添加到集合中
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static List<string> ReadFile(string path) 
        {
            List<string> list = new List<string>();
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(fs, System.Text.Encoding.GetEncoding("gb2312"));            
            string s = sr.ReadLine();
            while (s != null)
            {
                if (s.Length > 0)
                {
                    list.Add(s);
                }
                s = sr.ReadLine();
            }
            sr.Close();
            fs.Close();
            return list;
        }
        /// <summary>
        /// 数字转化为英文字符串 递归算法即可
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        static string NumberToEnglishString(int number) 
        {
            if (number < 0) //暂不考虑负数
            {
                return "";
            }
            if (number < 20) //0到19
            {
                switch (number)
                {
                    case 0:
                        return "zero";
                    case 1:
                        return "one";
                    case 2:
                        return "two";
                    case 3:
                        return "three";
                    case 4:
                        return "four";
                    case 5:
                        return "five";
                    case 6:
                        return "sex";
                    case 7:
                        return "seven";
                    case 8:
                        return "eight";
                    case 9:
                        return "nine";
                    case 10:
                        return "ten";
                    case 11:
                        return "eleven";
                    case 12:
                        return "twelve";
                    case 13:
                        return "thirteen";
                    case 14:
                        return "fourteen";
                    case 15:
                        return "fifteen";
                    case 16:
                        return "sixteen";
                    case 17:
                        return "seventeen";
                    case 18:
                        return "eighteen";
                    case 19:
                        return "nineteen";
                    default:
                        return "";
                }
            }
            if (number < 100) //20到99
            {
                if (number % 10 == 0) //20,30,40,...90的输出
                {
                    switch (number)
                    {
                        case 20:
                            return "twenty";
                        case 30:
                            return "thirty";
                        case 40:
                            return "forty";
                        case 50:
                            return "fifty";
                        case 60:
                            return "sixty";
                        case 70:
                            return "seventy";
                        case 80:
                            return "eighty";
                        case 90:
                            return "ninety";
                        default:
                            return "";
                    }
                }
  &n

C#编写程序将数字转换成英文:如32:thirty two ,123:one hundred and twenty three.说明:1、输入文件格式为input.txt,输出文件格式为output.txt;2、数字为正整数,长度不超过十位,不考虑小数,转化结果为 C# * 编写图形 (如三角形) 看不懂.不需要程序 编写一个C程序,从键盘输入一个数,将每一位数字转换为英文单词.如:输入9815,则输出:nine,eight,one,f 编写一个C#程序,将摄氏温度转换为华氏温度.static void Main(string[] args){int c;double f; c = int.Parse(Console.ReadLine());f = c* 9/ 5.0 + 32;Console.WriteLine(摄氏温度:{0},华氏温度:{1},c,f);} 在程序编写的时候为什么将输入的数字和汉字加上英文双引号 c语言 把英文数字 例如 one hundred and eleven 转换位数字 111;怎样编写程序,要求1~1000内的英文数字 C#数字怎么转换成汉字大写形式?如: 456789 ,转换成 四十五万六千七百八十九 编写程序,将摄氏温度(C)转换为华氏温度(F),转换公式为F=9C/5+32 用C#编写,输入一个整数将其各位数字颠倒顺序后输出 VB矩阵转置.编写程序将2*3的矩阵转置,即转换成3*2的矩阵. excel中如何将数字转换成英文货币 如何用C#编写简易计算器 、矩阵转置.编写程序将2*3的矩阵转置,即转换成3*2的矩阵.【提示】使用两个二维数组来完成.求程序 编写一个程序,将2小时25分钟转换成用分钟表示,输出转换前后的数值.(是用C语言编程) 用C#编写一个程序如何判断三角形形状 用C#语言怎样编写计算其程序? C#如何将英文日期转换成数字日期要求使日期例如:13JUL13此日期转换成:2013-7-13大虾们出出主意啊. C# 将字符串中元素加单引号如一个字符串:a1,a2,a3,a4转换为 'a1','a2','a3','a4'都好均为英文逗号