1005. Spell It Right (20)[C语言]

xiaoxiao2021-02-28  97

1005. Spell It Right (20)

时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue

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

#include <stdio.h> #include <stdlib.h> const char a[10][9] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" } ; void print( long long sum ){ if(sum / 10 !=0){ int r = sum ; print((sum-r) /10); printf( " %s",a[r] ); }else{ printf( "%s", a[sum] ); } } int main(){ long long sum = 0 ; char c ; scanf("%c" ,&c); while(c!='\n'){ sum=sum+((int)c)-48; scanf("%c" ,&c); } print(sum); return 0 ; }

转载请注明原文地址: https://www.6miu.com/read-64716.html

最新回复(0)