Spell It Right
来源:互联网 发布:音乐软件 编辑:程序博客网 时间:2024/05/15 02:13
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<cstring>using namespace std;char str[101];char numbers[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};int main(){cin>>str;int len=strlen(str),sum=0;for(int i=0;i<len;++i)sum+=(str[i]-'0');if(sum<10)cout<<numbers[sum];else if(sum<100){cout<<numbers[sum/10]<<" ";cout<<numbers[sum%10]<<endl;}else if(sum<1000){cout<<numbers[sum/100]<<" ";cout<<numbers[sum%10/10]<<" ";cout<<numbers[sum%10]<<endl;}return 0;}
0 0
- 1005. Spell It Right
- 1005. Spell It Right
- PAT1005.Spell It Right
- PAT_1005: Spell It Right
- PAT1005. Spell It Right
- 1005. Spell It Right
- 1005.Spell It Right
- pat1005 Spell It Right
- 1005. Spell It Right
- Spell It Right
- Spell It Right
- 1005. Spell It Right
- 1005. Spell It Right
- 1005 Spell it right
- 1005. Spell It Right
- 1005. Spell It Right
- Spell It Right
- 1005. Spell It Right
- 多线程简介
- Java proxy(java代理模式实例分析)
- PAT B1001 害死人不偿命的(3n+1)猜想 (15) (模拟)
- 【矩阵乘法经典应用】【ZOJ3497】【Mistwa】
- Leetcode: Construct Binary Tree from Preorder and Inorder Traversal
- Spell It Right
- 32-语言入门-32-Triangular Sums
- PAT B1032 挖掘机技术哪家强(20)(模拟)
- node.js开发手记
- #笔记#圣思园 JavaSE 第9讲——面向对象之 封装 encapsulation
- 红黑树(c实现)
- KPM
- 转屏幕时,EditText的setText()方法无效
- 最基本的理解和尊重