1005. Spell It Right (20)
来源:互联网 发布:cf手游安卓版飞天软件 编辑:程序博客网 时间:2024/05/17 07:44
http://www.patest.cn/contests/pat-a-practise/1005
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
#include <stdio.h>#define bool int#define false 0#define true 1int main(){char *num2char[] = {"zero","one","two","three","four","five","six","seven","eight","nine"};bool first = true;char chs[200]; //字符数组保存输入的数据(数据太大时long long貌似都不够)int A[200];//保存各位之和的每一位数字int sum,n;//sum-各位之和,n-暂存和的每一位char ch;//用于输入chs时暂存字符int i = 0,cnt;while( '\n' != (ch = getchar())){//输入数据chs[i++] = ch;}cnt = i;if(i == 1 && chs[0]=='0'){//输入只有一个0时printf("zero");return 0;}sum = 0;for(i = 0;i < cnt;++i){//计算各位之和sum = sum + (chs[i] + ( 0 - '0'));}cnt = 0;while(sum){//取和sum的各位保存到A[]n = sum % 10;sum = sum / 10;A[cnt++] = n;}cnt--;for(i = cnt;i >= 0 ;--i){if(first) first = false;//第一次打印时不打印空格else printf(" ");printf("%s",num2char[A[i]]);}return 0;}
0 0
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 开发者应当了解的WebKit知识
- 【翻译自mos文章】当 在os上的datafile已经不存在的情况下 将该tablespace删除
- 服务设计模式-请求/确认模式
- [视频] 开放物联网大会2014
- bzoj 2223: [Coci 2009]PATULJCI
- 1005. Spell It Right (20)
- 杭电1072---Nightmare
- 守护线程
- Linux程序设计(Linux shell编程一)
- HDOJ 1170 Balloon Comes!
- BZOJ2006 [NOI2010]超级钢琴(划分树+堆)
- POJ 2486 Apple Tree 树形DP
- mac运行appium报错:Appium will not work if used or installed with sudo
- hihoCoder:#1051 补提交卡