本文主要是介绍PAT A1005 Spell It Right (20分),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805519074574336
题目描述
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.
输入
Each input file contains one test case. Each case occupies one line which contains an N (≤10^100 ).
输出
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.
样例输入
12345
样例输出
one five
代码
#include <cstdio>int main() {char str[110];char num[11][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};int sum = 0, t = 0, temp[100];scanf("%s", str);for(int i = 0; str[i] != '\0'; i++)sum = sum + (str[i] - '0');do{temp[t++] = sum % 10;sum = sum / 10;}while(sum > 0);for(int i = t - 1; i >= 0; i--) {printf("%s", num[temp[i]]);if(i > 0)printf(" ");}printf("\n");return 0;}
这篇关于PAT A1005 Spell It Right (20分)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!