1002. 写出这个数 (20)
来源:互联网 发布:软件限制策略设置 编辑:程序博客网 时间:2024/06/10 08:46
1002. 写出这个数 (20)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100。
输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:1234567890987654321123456789输出样例:
yi san wu
#include<iostream>#include<string>using namespace std;int main(){string n = "";//存储输入字符串int sum = 0;int index = 0;char temp = 0;cin >> n;//计算各位之和for(;index<n.length();index++){temp = n[index];sum += (temp-'0');}//和的结果保存在sum中,要拆解的数是sum!string sum_str = "";char a = 0;index = 0;//将sum倒序拆解while (sum / 10){a = (sum % 10) + 48;sum_str += a;sum /= 10;index++;}sum_str += (sum + 48);//此时得到的sum_str是倒序for(;index>=0;index--){switch (sum_str[index]){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 (index)cout << " ";}return 0;}
对数字的拆解需要好好看看
要注意输出的格式,我才不会说因为忘记删测试的输出提交了好多次都不过【逃
0 0
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- 1002. 写出这个数 (20)
- dashboard项目
- 绘制不同的条形图
- WebStorm自动换行
- org.springframework.dao.DuplicateKeyException: a different object with the same identifier value was
- ORA-00600 [kcbchg1_12]
- 1002. 写出这个数 (20)
- 性能调优分析之:Oracle SQL执行计划报告生成器
- 折线图
- Android调试usb adb进程提前
- Windows下利用JMX监控Tomcat
- Web日程管理FullCalendar
- 常用正则
- 链表的操作
- tomcat6启动出现NullPointerException ReplicationValve.java:348问题的解决