读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100。
输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:1234567890987654321123456789输出样例:
yi san wu
主要的难点是,读入数据。
在C语言中的string比较奇怪,需要用到char[]。。。
好久不写,都忘记了。。。。
看来需要复习下了。
#include<stdio.h>
//#include<vector>
#include<string>
#include<iostream>
//#include<math.h>
using namespace std;
int main(void)
{
//__int64 n=0;
int res=0;
char num[101]={0};
char *tmp = num;
//string nn;
char ss[10][5] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
// vector<string> sp = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
//char sp[10][5] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
scanf("%s", num);
//scanf("%s", &nn);
//printf("%l64d", n);
//cout<<ss[0]<<endl;
while(*tmp != '\0')
{
res += (*tmp - '0');
tmp++;
}
char num_str[4] = {0};
sprintf(num_str,"%d",res);
char *pres = num_str;
int index=0;
while(*pres != '\0')
{
index = (*pres -'0');
//printf("%d",index);
printf("%s", ss[index]);
//cout<<ss[index]<<endl;
pres++;
if(*pres != '\0') printf(" ");
//else printf("\n");
}
return 0;
}