PAT (Advanced Level) Practice 1005 Spell It Right(简单的字符串处理)

Spell It Right

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.

Specification Input

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

Specification Output.

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


Sample Output

one five

题意: 给一个非负整数N,求出它各个位上的数字之和,并用英文输出,N(≤10^100)。

#include <stdio.h>
#include <string.h>

int main(){
	char s[105];
	char e[10][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
	scanf("%s", s);
	int sum = 0, len = strlen(s);
	for(int i = 0; i < len; i++) sum += s[i] - '0';
	if(sum >= 100) printf("%s ", e[sum / 100]);
	if(sum >= 10) printf("%s ", e[(sum / 10) % 10]);
	printf("%s", e[sum % 10]);
	return 0;


©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页