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:12345Sample Output:
one five
代码:
/************************************
This is a test program for anything
Enjoy IT!
************************************/
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <set>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
/*ifstream cin;
cin.open("in.txt");
ofstream cout;
cout.open("out.txt");*/
//////////////////////////////////////////////////////////////////////////
// TO DO Whatever You WANT!
string s1;
while (cin >> s1 )
{
int sum = 0;
list<string> out;
for (int i = 0; i < s1.length(); i++)
{
sum += s1[i] - '0';
}
do
{
switch (sum % 10)
{
case 0:
out.push_front("zero");
break;
case 1:
out.push_front("one");
break;
case 2:
out.push_front("two");
break;
case 3:
out.push_front("three");
break;
case 4:
out.push_front("four");
break;
case 5:
out.push_front("five");
break;
case 6:
out.push_front("six");
break;
case 7:
out.push_front("seven");
break;
case 8:
out.push_front("eight");
break;
case 9:
out.push_front("nine");
break;
}
sum /= 10;
} while (sum != 0);
int len = out.size();
for (int i = 0; i < len; i++)
{
if (i == 0)
{
cout << out.front();
}
else
{
cout << " " << out.front();
}
out.pop_front();
}
cout << endl;
}
//////////////////////////////////////////////////////////////////////////
// system("pause");
return 0;
}
解读编程技巧与技术领域
本文深入探讨了编程领域的核心技术,包括开发工具、算法、数据结构等,为开发者提供全面的技术指南。
387

被折叠的 条评论
为什么被折叠?



