您的位置:首页 > 其它

1005. Spell It Right (20)

2015-12-06 09:55 330 查看
注意字符串的输入方法

char a[100] = { 0 };

scanf("%s", &a);

[/code]

时间限制400 ms
内存限制65536 kB
代码长度限制16000 B
判题程序Standard作者CHEN, Yue
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
来源: <http://www.patest.cn/contests/pat-a-practise/1005>
#pragma warning(disable:4996)

/**/

#include <stdio.h>

#include <string.h>


using namespace std;

void PrintNum(int a);

int main(void){




char a[100] = { 0 };

int sum = 0,b=0;

scanf("%s", &a);

for (int i = 0; i < 100; i++){

if (a[i]!=0)

sum += (a[i] - '0');

}


if (sum >= 100){

b = sum / 100;

PrintNum(b);

printf(" ");

b = sum / 10 % 10;

PrintNum(b);

printf(" ");

b = sum % 10;

PrintNum(b);

}

else if (sum > 10){

b = sum / 10;

PrintNum(b);

printf(" ");

b = sum % 10;

PrintNum(b);


}

else{

PrintNum(sum);

}




return 0;

}

void PrintNum(int a){

if (a == 0){

printf("zero");

}

else if (a == 1)

printf("one");

else if (a == 2)

printf("two");

else if (a == 3)

printf("three");

else if (a == 4)

printf("four");

else if (a == 5)

printf("five");

else if (a == 6)

printf("six");

else if (a == 7)

printf("seven");

else if (a == 8)

printf("eight");

else if (a == 9)

printf("nine");

else;

}

[/code]

来自为知笔记(Wiz)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: