1005. Spell It Right (20)
2015-12-06 09:55
330 查看
注意字符串的输入方法
[/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:
[/code]
来自为知笔记(Wiz)
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:
12345Sample 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)
相关文章推荐
- Ajax 调用方式
- JDeveloper Memory And Performance
- LNMP搭建Discuz
- Fedora 23(Server Edition)中构建Mail Server(Postfix+Dovecot)
- 62,OC多文件开发
- win7下安装配置node.js+express开发环境
- LNMP环境搭建
- 【Leetcode】Remove Duplicates from Sorted Array II
- C#与Java泛型的比较
- jQuery创建ajax关键词数据搜索
- 获取浏览器ip地址
- php连接MySQL失败问题解决
- 1004. Counting Leaves (30)
- LeetCode 104:Maximum Depth of Binary Tree
- iOS/mac开发的一些知名个人博客
- EasyUI中文帮助文档
- 【Leetcode】Plus One
- 1003. Emergency (25)
- 大数乘法——POJ2389
- 一个我纠结很久的background和background-image关系区别问题