-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path0095.cpp
67 lines (62 loc) · 1.58 KB
/
0095.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
// 0095.人民币转换
#include <iostream>
using namespace std;
string ge[10] = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
string ot[17] = { "", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾",
"佰", "仟", "万", "拾", "佰", "仟","万" };
void readItAfterPlot(string num)
{
if(num == "00") {
cout << "整";
return ;
}
if (num[0] > '0') {
cout << ge[num[0]-'0'] << "角";
}
if (num[1] > '0') {
cout << ge[num[1]-'0'] << "分";
}
return ;
}
void readItBeforePlot(string s)
{
if (s == "0") return;
int j = s.size()-1;
if(!(j%4 == 1 && s[0] == '1')) {
cout << ge[s[0]-'0'];
}
cout << ot[j];
for(int i = 1; i < s.size(); i++)
{
if( (j-i)%4 == 0 && s[i] == '0') {
if (i >= 4 && j-i == 4 && s[i-1] + s[i-2] + s[i-3] == '0'*3) continue; // 100000001.11
cout << ot[j-i];
continue;
}
if(s[i] != '0') {
if(s[i-1] == '0') cout << "零";
//if(!((j-i)%4 == 1 && s[i] == '1')) {
// 513.00 是伍佰壹拾叁元还是伍佰拾叁元的区别。
cout << ge[s[i]-'0'];
//}
cout << ot[j-i];
}
}
cout << "元";
return ;
}
int main()
{
string s;
while(getline(cin, s))
{
int idx = s.find('.');
string t1 = s.substr(0, idx);
string t2 = s.substr(idx+1);
cout << "人民币";
readItBeforePlot(t1);
readItAfterPlot(t2);
cout << endl;
}
return 0;
}