一个输入数字转化为大写的小程序(用到递归)(转)

在sina blog上看到的一篇文章,因为可能会用到,所以先收藏下来,代码未经过验证~~~

using System;
using System.Collections.Generic;
using System.Text; 

namespace Capp
{
    
class Program
    
{
        
const string numstr = "零壹贰叁肆伍陆柒捌玖";
        
const string numstr1 = "  拾佰千";
        
const string numstr2 = " 万亿";
        
static string sout;
        
static int ln;
        
static void Main(string[] args)
        
{
            
string num = Console.ReadLine();
            
long l = long.Parse(num);
            sout 
= "";
            s1(l);
            ln 
= 0;
            sout 
= sout.Replace(" """);
            sout 
= sout.Replace("零佰""").Replace("零千""").Replace("零拾""");
            
while (sout.IndexOf("零零">= 0)
            
{
                sout 
= sout.Replace("零零""");
            }

            sout 
+= "";
            sout 
= sout.Replace("零整""").Replace("零万""");
            Console.WriteLine(sout);
        }

        
static void s1(long x){
            
long n = x % 10000;
            
string s = "" + n;
            
string stmp="";
            
for (int i =0 ; i<s.Length; i++)
            
{
                
int m = int.Parse("" + s[i]);
                stmp
+= ""+numstr[m] + numstr1[s.Length-i];
            }

            stmp 
+=  numstr2[ln]; 

            sout 
= stmp + sout;
            ln
++;
            
if (ln == 3)
                ln 
= 0;
            
long l = x / 10000;
            
if (l > 0)
                s1(l);
        }

    }

}

posted @ 2007-10-18 11:11  kidman  阅读(266)  评论(0编辑  收藏  举报