0
点赞
收藏
分享

微信扫一扫

1005 Spell It Right (20 分)

Ad大成 2022-01-09 阅读 62
c++

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
#include<iostream>
using namespace std;
#include<string>
string yinwen[10] = { "zero","one","two","three","four","five","six","seven","eight","nine" };
int main() {
	string input;
	cin >> input;
	int temp = 0;
	int len = input.length();
	for (int cnt = 0; cnt < len; cnt++) {
		temp += input[cnt] - '0';
	}
	string output = to_string(temp);
	for (int cnt = 0; cnt < output.length(); cnt++) {
		int temp = output[cnt] - '0';
		cout << yinwen[temp] << (cnt != output.length() - 1 ? " " : "");
	}
	return 0;
}

 

举报

相关推荐

0 条评论