`

1005. Spell It Right (20)

c++ 
阅读更多
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>
#include <string.h>

using namespace std;

string map[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};

int main()
{
	string num,result = "";
	int sum = 0;
	cin>>num;
	for(int i=0;i<num.length();i++){
		sum += num[i]-48;
	}
	if(sum == 0){
		cout<<map[sum]<<endl;
		return 0;
	}
	while(sum>0){				//To change a integer to a string
		result = map[sum%10]+" "+result;
		sum /= 10;
	}
	string s = result.substr(0,result.length()-1);
	cout<<s<<endl;
	return 0;
} 


简单水过!

0
1
分享到:
评论

相关推荐

    pat题目分类.docx

    1005 Spell It Right (20 分)【int与string互换,hash打表】 1082 Read Number in Chinese (25 分)【将数字转成中文】 1093 Count PAT's (25 分)【PAT计数】 1071 Speech Patterns (25 分)【如何将词...

    ComponentOne IntelliSpell2012 v3

    Improve the Quality of Your Documentation: Spell-check XML documentation comments in your code as you type, right in Visual Studio. It’s Easy: Identify misspelled words in an entire solution with ...

    ComponentOne IntelliSpell 2013 v1

    Improve the Quality of Your Documentation: Spell-check XML documentation comments in your code as you type, right in Visual Studio. It’s Easy: Identify misspelled words in an entire solution with ...

    Pro OpenGL ES for Android

    ” Twenty-six years later I am still working on it and hope to get it right one of these days. Back then my dream device was something I could slip into my pocket, pull out when needed, and aim it at ...

    Python Text Processing with NLTK 2.0 Cookbook.pdf

    Natural Language Processing is used everywhere—in search engines, spell checkers, mobile phones, computer games, and even in your washing machine. Python's Natural Language Toolkit (NLTK) suite of ...

    VB编程资源大全(英文源码 其它)

    6 , chunks.zip This will open a file and read it in "Chunks" of a selected file.&lt;END&gt;&lt;br&gt;7 , logging.zip This is a bas that will log installation procedures so the file can be removed later....

    WPTools.v6.29.1.Pro

    - With Delphi XE2 or XE3 it is possible to compile WPTools into a 64 bit applications. You need WPTools 6 PRO or WPTools 6 Premium for this. - Localization and Inch/CM selection see ...

    Solr in Action最新完整版

    It offers key features like multi-lingual keyword searching, faceted search, intelligent matching, and relevancy weighting right out of the box. Solr in Action is the definitive guide to implementing...

    ManageabilityResourceTranslatorTool

    This open source tools makes it easier to internationalize .NET application into many ... This tool makes use of .NET version 3.5 because it uses a new text control that allows for spell checking.

    Solr in Action 英文版完整版

    It offers key features like multi-lingual keyword searching, faceted search, intelligent matching, and relevancy weighting right out of the box. Solr in Action is the definitive guide to implementing...

    UE(官方下载)

    The benefit of a column maker is that it can help you to format your text/code, or in some cases to make it easier to read in complex nested logic. Quick Open UltraEdit and UEStudio provide multiple ...

    visual assist v 10.4.1632 with crack

    (case=5567, case=7457) 6027, 6021 Listboxes are positioned such that they are not truncated at the right edge of the screen. (case=5178) Listbox remains on the same side of a symbol (either ...

Global site tag (gtag.js) - Google Analytics