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
原创粉丝点击