标签:
题目链接:http://acm.swust.edu.cn/problem/0552/
数钱啦~~~输入一个数字,小于999999999999,我们需要把他们转换为拼音,我们规定例如1234000567的念为“1十2亿3千4百万零5百6十7”具体见输入输出
一个数字N
数字加拼音,见SAMPLE OUTPUT
Sample Input
999999999999
123456000
1234000567
|
9qian9bai9shi9yi9qian9bai9shi9wan9qian9bai9shi9
1yi2qian3bai4shi5wan6qian
1shi2yi3qian4baiwanling5bai6shi7
|
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 int ar[15], len; 5 long long n; 6 string s,p[] = { "","shi", "bai", "qian", "wan", "shi", "bai", "qian", "yi", "shi", "bai", "qian" }; 7 void change(){ 8 reverse(s.begin(), s.end()); 9 int i, flag = 0; 10 for (i = s.size()-1; i >= 0;){ 11 if (s[i]-‘0‘){ 12 flag = 0; 13 cout << s[i] << p[i]; 14 i--; 15 } 16 else{ 17 //两个条件不能交换位置如果是6000,则最后一次i=-1,s[-1]无法访问(Runtime Error一次) 18 while (i>=0&&!(s[i]-‘0‘)){ 19 if (!(i % 4 )&& !flag){ 20 flag = 1; 21 cout << p[i]; 22 } 23 i--; 24 } 25 if (i >= 0)cout << "ling"; 26 } 27 } 28 cout << endl; 29 } 30 31 int main(){ 32 while (cin>>s) 33 change(); 34 return 0; 35 }
标签:
原文地址:http://www.cnblogs.com/zyxStar/p/4582168.html