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

很简单的题,最开始错了两次,N最大是10得100次方,用整形存储肯定不够,用字符串存储后就过了

#include <iostream>
#include <string>
#include <map> using namespace std; map<char,string> m;
int result[]; int main()
{
m[]="zero";
m[]="one";
m[]="two";
m[]="three";
m[]="four";
m[]="five";
m[]="six";
m[]="seven";
m[]="eight";
m[]="nine";
string n;
long int sum=;
cin>>n;
int b,i=;
while(n[i]!='\0'){
b=n[i]-;
sum=sum+b;
i++;
}
int x,countnum=;
while(sum){
x=sum%;
result[countnum]=x;
countnum++;
sum=sum/;
}
cout<<m[result[countnum-]];
for(int i=countnum-;i>=;i--){
cout<<" "<<m[result[i]];
} return ;
}

1005. Spell It Right (20)的更多相关文章

  1. PAT 甲级 1005 Spell It Right (20)(代码)

    1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...

  2. PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏

    1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  3. PTA 1005 Spell It Right (20)(20 分)水题

    1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...

  4. 1005 Spell It Right (20分)

    1005 Spell It Right (20分) 题目: Given a non-negative integer N, your task is to compute the sum of all ...

  5. PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...

  6. 1005 Spell It Right (20)(20 point(s))

    problem Given a non-negative integer N, your task is to compute the sum of all the digits of N, and ...

  7. PAT 甲级 1005. Spell It Right (20) 【字符串】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1005 思路 因为 n <= 10^100 所以 要用字符串读入 但是 100 * 100 ...

  8. PAT (Advanced Level) 1005. Spell It Right (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  9. PAT甲题题解-1005. Spell It Right (20)-数位求和,水

    把每个位上的数字求和sum,然后以英文单词的形式输出sum的每个位 #include <iostream> #include <cstdio> #include <alg ...

随机推荐

  1. TIJ——Chapter Five:Initialization & Cleanup

    Method overloading |_Distinguishing overloaded methods If the methods hava the same name, how can Ja ...

  2. hp-pa安装oracle和bash

    一.安装oracle数据库 安装之前先进行环境检查: 1.检查系统版本 #uname -a 2.查看内存大小 #/usr/contrib/bin/machinfo | grep -i Memory 3 ...

  3. JAVA-JNI java程序调用c/c++程序

    目的:写c/c++函数,让java调用 java代码 1.创建HelloJNI.java文件->编写代码如下->cmd中javac HelloJNI.java获取HelloJNI.clas ...

  4. css实现三角效果

    demo     <!DOCTYPE html> <html lang="zh"> <head> <meta charset=utf-8& ...

  5. 开通博客的第一天上传我的C#基础笔记,个人觉得很好用。

    1.索引器  string arrStr = "sddfdfgfh";  索引器的目的就是为了方便而已,可以在该类型的对象后面直接写[]访问该对象里面的成员  Console.Wr ...

  6. HTML5--拖动02-dragstart、drag、dragenter、dragover、dragleave、drop、dragend属性

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  7. 使用Apache Ambari管理Hadoop

    随着Hadoop越来越普及,对合适的管理平台的需求成为当前亟待解决的问题.已经有几个商业性的Hadoop管理平台,如Cloudera Enterprise Manager,但Apache Ambari ...

  8. nfc相关

    nfc普通读卡写卡按厂商API操作即可,但是牵扯到NDEF的读写就另当别论了,算是二次开放了,android手机有成熟的接口,.net也有一些,github上有一个,还没研究, https://git ...

  9. jqGrid subGrid配置 如何首次加载动态展开所有的子表格

    有时候需求需要默认加载表格的时候把子表格的数据也显示出来,经过研究相关SubGrids API配置如下: 属性 类型 描述 默认值 subGrid boolean 设置为true启用子表格.如果启用子 ...

  10. win10+PHP7

    在D盘自定义新建文件夹ApacheServer 再在ApacheServer文件夹下分别建立php,Apache,mysql,web四个文件夹分别用来存放 php,apache,mysql,项目文件 ...