写出这个数
来源:互联网 发布:共享经济 知乎 编辑:程序博客网 时间:2024/06/05 14:59
读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100。
输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1空格,但一行中最后一个拼音数字后没有空格。
输入样例:
1234567890987654321123456789
输出样例:
yi san wu
【C++程序】
---------------
#include <iostream>#include <string>#include <cmath>using namespace std;int main() {string str;getline(cin, str); // 读取大整数int sum = 0; for(int i = 0; i < str.size(); ++i)sum += str[i] - '0';// 求和 int temp = sum;int count = 0;while(temp > 0) { // 计算和的位数 ++count;temp /= 10;}--count;while(count >= 0) {// 分离和的数字 int bit = (sum / (int)pow(10, count)) % 10;switch(bit) {case 0:cout << "ling";break;case 1:cout << "yi";break;case 2:cout << "er";break;case 3:cout << "san";break;case 4:cout << "si";break;case 5:cout << "wu";break;case 6:cout << "liu";break;case 7:cout << "qi";break;case 8:cout << "ba";break;case 9:cout << "jiu";break;}if(count != 0)cout << " ";--count;}cout << endl;return 0;}
0 0
- 写出这个数
- PAT-写出这个数
- 1002 写出这个数
- 写出这个数
- 1002. 写出这个数
- 写出这个数 (20)
- 写出这个数
- 1002. 写出这个数
- 1002. 写出这个数
- 1002. 写出这个数
- pat1002,写出这个数
- PAT1002 写出这个数
- 1002写出这个数
- PAT1002. 写出这个数
- 1002、写出这个数
- 1002.写出这个数
- PAT.写出这个数
- 1002. 写出这个数
- java-职责链模式
- 【Python学习记录】2015-02-17
- NYOJ--36(动态规划)-题目----------------------------- 最长公共子序列
- (hdu step 4.2.3)Knight Moves(求从起点是否能够到达终点的最小步数)
- 害死人不偿命的(3n+1)猜想
- 写出这个数
- 2015.02.最新面试题总结(I)
- 我要通过!
- 成绩排名
- Java中的流,可以从不同的角度进行分类。
- 提交app Store审核时,Missing 64-bit support问题的解决办法
- python控制流语句-while,for,if
- Android | Vuforia 播放视频
- 【json】JsonFX