n年没写算法题了,今天用了20分钟写了一个,要求如题,感觉算法有所退步,老了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Text;
namespace  money
{
     class  Program
     {
         static  void  Main(string[] args)
         {
             StringBuilder sb= new  StringBuilder();
             var  strValue = Console.ReadLine();
             var  strlist = strValue.Split( '.' );
             if  (strlist.Length >=  2 )
             {
                 var  temp = strlist[ 1 ];
                 if  (temp.Length >=  2 )
                 {
                     if  (temp[ 0 ] !=  '0' )
                         sb.Append(GetChinese(Convert.ToInt32(temp[ 0 ].ToString()))).
                             Append( "角" ).
                             Append(GetChinese(Convert.ToInt32(temp[ 1 ].ToString()))).
                             Append( "分" );
                     else
                         sb.Append(GetChinese( 0 ));
                 }
                 else
                     sb.Append(GetChinese(Convert.ToInt32(temp[ 0 ].ToString()))).Append( "角" );
             }
             int  stateNum =  0 ;
             int  tempNum = Convert.ToInt32(strlist[ 0 ]);
             string outline = string.Empty;
             while  (tempNum> 0 )
             {
                 int  g = tempNum% 10 ;
                 if  (g ==  0 )
                 {
                     outline += (stateNum!= 0 )?GetChinese(g):string.Empty;
                     while  (g ==  0 )
                     {
                         stateNum++;
                         tempNum = tempNum /  10 ;
                         g = tempNum %  10 ;
                     }
                 }
                 else
                 {
                     outline += (stateNum <=  4 ) ? GetDW(stateNum) : GetDW((stateNum +  1 ) /  4 );
                     outline += GetChinese(g);
                     tempNum = tempNum /  10 ;
                     stateNum++;
                 }
                 if  (stateNum ==  5 )
                     stateNum++;
             }
             string right = string.Empty;
             for  ( int  i = outline.Length- 1 ; i >=  0 ; i--)
             {
                 right += outline[i].ToString();
             }
             Console.WriteLine(right+sb.ToString());
             Console.ReadKey();
         }
         private  static  string GetDW( int  i)
         {
             switch  (i)
             {
                 case  0 :
                     return  "元" ;
                 case  1 :
                     return  "十" ;
                 case  2 :
                     return  "百" ;
                 case  3 :
                     return  "千" ;
                 case  4 :
                     return  "万" ;
             }
             return  null ;
         }
         private  static  string GetChinese( int  i)
         {
             switch  (i)
             {
                 case  1 :
                     return  "一" ;
                 case  2 :
                     return  "二" ;
                 case  3 :
                     return  "三" ;
                 case  4 :
                     return  "四" ;
                 case  5 :
                     return  "五" ;
                 case  6 :
                     return  "六" ;
                 case  7 :
                     return  "七" ;
                 case  8 :
                     return  "八" ;
                 case  9 :
                     return  "九" ;
                 case  0 :
                     return  "零" ;
             }
             return  null ;
         }
     }
}