1005 Spell It Right (20分)

题目:

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的每一位合,然后用英语读每一位。

题解:

#include <iostream>
using namespace std; int main() {
long long sum = 0;
string n;
cin >> n;
for(int i=0;i<n.size();i++) sum+=(n[i]-'0');
string ans = to_string(sum);
string tamp[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
for(int i=0;i<ans.size();i++) {
if(i) cout << " ";
cout << tamp[ans[i]-'0'];
}
return 0;
}

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

  1. 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 ...

  2. PAT Advanced 1005 Spell It Right (20 分)

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

  3. PAT (Advanced Level) Practice 1005 Spell It Right (20 分) (switch)

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

  4. 【PAT甲级】1005 Spell It Right (20 分)

    题意: 给出一个非零整数N(<=10^100),计算每位之和并用英文输出. AAAAAccepted code: #include<bits/stdc++.h> using name ...

  5. 1005 Spell It Right (20 分)

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

  6. Day 006:PAT练习--1005 Spell It Right (20 分)

    上星期一直在写报告乱七八糟的,从今天开始不刷乙级的了,还是多刷甲级进步来得快一点! 显而易见,该题的关键在于将输入之和的每一位从高到低输出,这里我们发现题意中的输入数的范围为0-10^100,显然我们 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. vue2.x学习笔记(五)

    接着前面的内容:https://www.cnblogs.com/yanggb/p/12571062.html. 计算属性 模板内的表达式非常便利,但是设计它们的初衷是用于简单运算的.如果在模板中放入太 ...

  2. Python 如何移除旧的版本特性,如何迎接新的特性?

    2020 年 4 月 20 日,Python 2 的最后一个版本 2.7.18 发布了,这意味着 Python 2 是真正的 EOL(end of life)了,一个时代终于落幕了. Python 2 ...

  3. MySQL 主从复制:基于二进制文件复制配置详解

    MySQL-主从复制:基于二进制文件复制详解 前言 主从复制是指把一个MySQL的数据库服务器作为主服务器(master),然后把master的数据复制到一个或者多个MySQL数据库服务器作为从服务器 ...

  4. 获取某个时间开始 之后的 N次[周几,周几]

    废话不多说,直接上菜! 调用函数代码举例 //PS :这里需要注意的是 周日 是 0 !!!!! console.log(getBeforeDate(-10000)) //一万天之后的日期 conso ...

  5. Ubuntu 安装 Qt, 安装辅助软件

    sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev sudo apt-get install gcc g++ sudo apt-get inst ...

  6. 为何 UNIX 时间 0, 有时显示是1970年1月1日,有时显示是1969年12月31日

    by Rachael Arnold http://www.rachaelarnold.com/dev/archive/why-is-date-returning-wrong Demystifying ...

  7. ReportEventA 错误 ERROR_CRC

    如果 level 的宏弄错了,就会出现这种奇怪的现象.

  8. 【JAVA基础】11 Scanner类

    1. Scanner的概述 一个可以使用正则表达式来解析基本类型和字符串的简单文本扫描器. Scanner 使用分隔符模式将其输入分解为标记,默认情况下该分隔符模式与空白匹配.然后可以使用不同的 ne ...

  9. Pycharm中设置encoding

    在Pycharm专业版中,为了防止文件在别的机器上出现乱码,所以需要进行字符编码的设置. 首先在Pycharm中的View中将下图中的Toolbar打上勾. 接着,工具栏就会出现,选中settings ...

  10. java 接口实现关系下的多态

    2019独角兽企业重金招聘Python工程师标准>>> 多态: 父类的引用类型变量指向了子类的对象 或者 是接口类型的引用类型变量指向了接口实现类的对象. 实现关系下的多态:    ...