PAT-A 1005. Spell It Right (20)(20 分)十进制转D进制-基础题

https://pintia.cn/problem-sets/994805342720868352/problems/994805519074574336

1005 Spell It Right (20)(20 分)提问

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.

Input Specification:

Each input file contains one test case. Each case occupies one line which contains an N (<= 10^100^).

Output Specification:

For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.

Sample Input:

12345

Sample Output:

one five
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std; 
char e[10][8]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main(int argc, char** argv) {
	char s[1001];
	scanf("%s",s);
	int len=strlen(s);
	int sum=0;
	for(int i=0;i<len;i++){
		sum+=s[i]-'0';
	}
	//printf("%d",sum);
	int num[1001];
	int index=0;
	do{
		num[index++]=sum%10;
		sum/=10;
	}while(sum!=0);
	for(int i=index-1;i>0;i--){
		printf("%s ",e[num[i]]);
	}printf("%s",e[num[0]]);
	return 0;
}

 

    原文作者:进制转换
    原文地址: https://blog.csdn.net/qian2213762498/article/details/81280836
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞