PAT-A 1005. Spell It Right
来源:互联网 发布:js radio 多选 编辑:程序博客网 时间:2024/05/27 00:33
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<stdio.h>#include<string.h>#define MAX 101char c[MAX];char ans[MAX]={0};char set[][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};void num_to_char(int n);int main(){ scanf("%s",c); int len = strlen(c),i,sum = 0; for(i=0;i<len;i++) { sum = sum + c[i]-'0'; } num_to_char(sum); len = strlen(ans); for(i=len-1;i>=0;i--) { printf("%s",set[ans[i]-'0']); if(i!=0) putchar(' '); } return 0;}void num_to_char(int n){ if(n==0) { ans[0] = '0'; ans[1]= '\0'; return; } int i=0; while(n!=0) { ans[i] = n%10 + '0'; i++; n=n/10; } ans[i] = '\0'; return;}
0 0
- PAT A 1005. Spell It Right (20)
- PAT A 1005. Spell It Right
- PAT(A) - 1005. Spell It Right (20)
- PAT-A 1005. Spell It Right
- pat-a 1005. Spell It Right (20)
- PAT A 1005. Spell It Right (20)
- PAT-A 1005. Spell It Right (20)
- PAT-A-1005. Spell It Right (20)
- PAT-A 1005. Spell It Right (20)
- pat 1005. Spell It Right
- PAT 1005. Spell It Right
- PAT:1005. Spell It Right
- 【PAT】1005. Spell It Right
- PAT-A | 1005 | Spell It Right
- (PAT)1005. Spell It Right (20)
- PAT 1005. Spell It Right (20)
- PAT: 1005. Spell It Right (20)
- PAT(Advanced level) 1005. Spell It Right
- 2016Android重要的app地址
- 在Mac环境安装Caffe环境(CPU_ONLY)
- 剑指offer-----面试题29(数组中出现次数超过一半的数字)
- 仿QQ空间,百思不得姐下拉刷新图片放大
- 关于Marathon-lb
- PAT-A 1005. Spell It Right
- 自定义URL Scheme完全指南
- Java 类加载
- 华为OJ 字符串排序
- Swift基础语法-枚举,枚举原始值,枚举相关值,switch提取枚举关联值
- CentOS7安装mysql5.6
- mysql-5.7.14解压版安装教程
- java学习之路 之 面向对象编程-面向对象-第一个小项目P1-FAACS
- 笔记①:动态规划之背包问题九讲