PET 1002题目

来源:互联网 发布:雪梨的淘宝店有哪几个 编辑:程序博客网 时间:2024/05/16 12:00

有点无语,不知道数据应该怎么输入了....直接上代码,图中代码注释的部分是我原来写的。。。


读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。

输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100

输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 空格,但一行中最后一个拼音数字后没有空格。

输入样例:
1234567890987654321123456789
输出样例:
yi san wu
#include <iostream>#include <cmath>#include <stdio.h>#include <string.h>using namespace std;int main( ){string listChinese[] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};char a[101] = { 0 };char numStr[ 5 ] = { 0 };char *ap;int total = 0;//strcpy( a, "1234567890987654321123456789" );scanf("%s",a);ap = a;while ( *ap != '\0' ){total += (*ap - '0');ap++; }sprintf( numStr, "%d", total );ap = numStr;for( ap = numStr; ;ap++){if( *ap == '\0' ){printf("\n");break;}else if( *(ap+1) == '\0' ){cout << listChinese[ *ap - 48 ]; //printf( listChinese[ 0 ] );}else{cout << listChinese[ *ap - 48 ];printf( " " );}}}


                                             
0 0
原创粉丝点击