-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumberToChinese.cpp
77 lines (71 loc) · 1.35 KB
/
numberToChinese.cpp
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
//读取文件
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<stack>
//
using namespace std;
int main(){
string s;
cin >> s;
int a[10] = { 0 };
int length = s.length();
for (int i = 0; i < length; i++){
a[i] = s[i] - '0';
}
cout << length;
int count = 0;
while (length)
{
switch ((a[count]))
{
case 9: cout << "九"; break;
case 8: cout << "八"; break;
case 7: cout << "七"; break;
case 6: cout << "六"; break;
case 5: cout << "五"; break;
case 4: cout << "四"; break;
case 3: cout << "三"; break;
case 2: cout << "二"; break;
case 1: cout << "一"; break;
case 0:
{
if (count == 1 || count == 3) cout << "零";
else if (count == 7) ;
else cout << "零";
break;
}
default:
break;
}
if (length == 7 || length == 4||length ==2){
if (a[length-1] == 0){
cout << "";
}
else{
if (length == 7) cout << "百";
else if (length== 2) cout << "十";
else cout << "千";
}
}
else{
switch (length)
{
case 9: cout << "亿"; break;
case 8: cout << "千"; break;
case 6: { if (a[count] == 0);
else cout << "十"; break;
}
case 5: cout << "万"; break;
case 3: cout << "百"; break;
case 2: cout << "十"; break;
default:
break;
}
}
length--;
count++;
}
return 0;
}