1005. Spell It Right (20)

来源:互联网 发布:jmeter 相应数据乱码 编辑:程序博客网 时间:2024/05/15 23:48

这个题简单,就直接贴在这吧,注意一点输入数据规模比较大,要用char来存储


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
// 1005. Spell It Right.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include<iostream>#include<vector>#include<string>using namespace std;void printSpelling(int number){switch (number){case 0:cout << "zero";break;case 1:cout << "one";break;case 2:cout << "two";break;case 3:cout << "three";break;case 4:cout << "four";break;case 5:cout << "five";break;case 6:cout << "six";break;case 7:cout << "seven";break;case 8:cout << "eight";break;case 9:cout << "nine";break;default:break;}}int _tmain(int argc, _TCHAR* argv[]){vector<char> input;char temInput;//输入while (true){temInput = cin.get();if (temInput == '\n')break;input.push_back(temInput);}//求和int sum = 0;for (int i = 0; i < input.size(); i++)sum += input[i] - '0';//输出vector<int> output;if (sum == 0)output.push_back(0);elsewhile (sum > 0){output.push_back(sum % 10);sum = sum / 10;}//打印for (int i = 0; i < (int)output.size() - 1; i++){printSpelling(output[output.size()-i-1]);cout << " ";}//打印最后一个if (output.size() > 0)printSpelling(output[0]);system("pause");return 0;}


0 0
原创粉丝点击