1005. Spell It Right

来源:互联网 发布:网络韩语翻译兼职 编辑:程序博客网 时间:2024/06/09 13:31

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.

#include <stdio.h>#include <stdlib.h>#include <string.h>#define N 110int Change (char c);void Draw (char a);int main (){    long sum=0;    char num[N];    gets(num);    int i;    for( i=0;i<strlen(num);i++)    {         sum+=Change(num[i]);         }              char str[N];    sprintf(str,"%d",sum);    for( i=0;i<strlen(str)-1;i++)    {         Draw(str[i]);         printf(" ");         }    Draw(str[i]);    printf("\n");    system("pause");    return 0;    }void Draw (char a){     switch (a)     {            case '0':printf("zero");return;            case '1':printf("one");return;            case '2':printf("two");return;            case '3':printf("three");return;            case '4':printf("four");return;            case '5':printf("five");return;            case '6':printf("six");return;            case '7':printf("seven");return;            case '8':printf("eight");return;            case '9':printf("nine");return;            }     }int Change (char c){    return c-'0';    }

0 0
原创粉丝点击