1005. Spell It Right (20)

来源:互联网 发布:json解析框架 编辑:程序博客网 时间:2024/06/08 19:25

PAT

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<cstdio>#include<cstring>using namespace std;int main(){    char c[10][20]={"zero","one","two","three",    "four","five","six","seven","eight","nine"};    char a[100],b[100];    scanf("%s",a);    int sum=0;    for(int i=0;i<strlen(a);i++)//加和         sum+=a[i]-'0';    sprintf(b,"%d",sum);//字符串和整型互换     printf("%s",c[b[0]-'0']);//输出第一位     for(int i=1;i<strlen(b);i++)        printf(" %s",c[b[i]-'0']);    return 0; } 
0 0
原创粉丝点击