a1005. Spell It Right (20)
来源:互联网 发布:西游之路坐骑进阶数据 编辑:程序博客网 时间:2024/06/02 04:47
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
最多10的100次方,就是longlong型 不够,但是相加结果最多900,int型就够了,先用字符串储存大整数。
AC代码:
#include <iostream>#include <vector>#include <string>using namespace std;vector<string> number(10);int main(){number[0]="zero";number[1]="one";number[2]="two";number[3]="three";number[4]="four";number[5]="five";number[6]="six";number[7]="seven";number[8]="eight";number[9]="nine";int r=0;string num;cin>>num;for(int i=0;i<num.length();i++){r+=num[i]-'0';}//cout<<"r "<<r<<endl;if(r>=100){cout<<number[r/100]<<" ";}if(r>=10){cout<<number[(r/10)%10]<<" ";}cout<<number[r%10];}
数字转字符串可以用sprintf函数
0 0
- a1005. Spell It Right (20)
- A1005. Spell It Right (20)
- A1005.Spell It Right(20)
- PAT:A1005. Spell It Right (20/20)
- 【PAT】 A1005. Spell It Right (20)
- PAT---A1005. Spell It Right (20)
- PAT A1005. Spell It Right (20)
- PAT A1005 Spell It Right(20)
- PAT A1005 Spell It Right
- PAT A1005. Spell It Right
- PAT-A1005. Spell It Right (20)(模拟)
- 1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005 Spell It Right (20)
- PAT1005. Spell It Right (20)
- 项目14-三角形类雏形(3)
- 数组指针和指针数组
- 送伞
- 28 map
- ## BaseAdapter的优化 ##
- a1005. Spell It Right (20)
- 【HDOJ 5653】 Bomber Man wants to bomb an Array.(DP)
- HDOJ 5651-xiaoxin juju needs help【字符的全排列】
- 红黑树代码实践
- 归园田居 东晋 陶渊明 注音版
- AOJ2249Contest Page(最短路径spfa)
- 借助SystemBarTint实现透明标题栏(沉浸式)
- 最近对问题,分治法求解
- Android Studio 2.1 Preview 4 发布,以及新增的两点攺动.