PAT - 甲级 - 1005. Spell It Right (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 (<= 10100).

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

题目大概意思:第一行给出一个不大于10^100数,将各个位上的数组相加的和 用英文输出相加的和各个位置的数字,如12345,1+2+3+4+5=15  输出 one five;

10^100肯定不能用int   long long  定义一个字符数组保存  char num[101]即可;

输出的话,先用取余的方法将各个位数组存储到另一个数组中,然后逆序输出即可(因为取余是从低位取到高位);



#include
#include
#include
using namespace std;
string print1[10] ={"zero","one","two","three","four","five","six","seven","eight","nine"}; 
int numPrint[101];
int main(){
	char num[101];
	scanf("%s",num);
	int len = strlen(num);
	int sum = 0;
	for(int i=0 ;i10){
			numPrint[n] = sum%10;
			sum /= 10;
			n++;
		}
		numPrint[n] = sum; //别忘了处理最后一位 
		
		for(int i=n ;i>=0 ;i--){

			if(i==n){
				cout<




你可能感兴趣的:(PAT,(Advanced,Level))