PAT_1005

1005. Spell It Right (20)

時間限制
400 ms
內存限制
32000 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 <string>
#include <iostream>
#include <sstream>
using namespace std;


int main(){
	string english[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
	string str;
	int sum=0;
	getline(cin,str);
	string::const_iterator it = str.begin();
	while(it!=str.end()){
		int temp;
		temp=(*it)-'0';
		sum+=temp;
		++it;
	}
	str.clear();
	stringstream ss;
	ss<<sum;
	str=ss.str();
	it=str.begin();
	while(it!=(str.end()-1)){
		cout<<english[*it-'0']<<" ";
		++it;
	}
	cout<<english[*it-'0'];
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章