https://pintia.cn/problem-sets/994805342720868352/problems/994805519074574336

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 (<= 10^100^).

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 <bits/stdc++.h>
using namespace std; char s[1111], num[1111];
char a[20][50] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; void itoa(int x) {
if(x == 0) {
num[0] = '0';
num[1] = 0;
return ;
}
stack<int> st;
while(x) {
st.push(x % 10);
x = x / 10;
}
int sz = 0;
while(!st.empty()) {
num[sz++] = (char)(st.top() + '0');
num[sz] = 0;
st.pop();
}
} int main() {
scanf("%s", s);
int len = strlen(s);
int sum = 0;
for(int i = 0; i < len; i ++) {
sum += s[i] - '0';
} itoa(sum);
int lenum = strlen(num); for(int i = 0; i < lenum; i ++) {
printf("%s", a[num[i] - '0']);
printf("%s", i != lenum - 1 ? " " : "\n");
}
return 0;
}

  

PAT 甲级 1005 Spell It Right的更多相关文章

  1. PAT 甲级 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 th ...

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

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

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

  4. PAT甲1005 Spell it right【字符串】

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

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

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

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

  7. PAT甲级1005水题飘过

    题目分析:用一个字符串输入之后遍历每一位求和后,不断%10获取最后一位存储下来,逆序用对应的英文单词输出(注意输入为0的情况) #include<iostream> #include< ...

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

  9. PAT甲级——A1005 Spell It Right

    题目描述 Given a non-negative integer N, your task is to compute the sum of all the digits of N, and out ...

随机推荐

  1. python学习之简介与环境安装

    [转自]http://www.cnblogs.com/wupeiqi/articles/5433925.html --Python可以应用于众多领域 如:数据分析.组件集成.网络服务.图像处理.数值计 ...

  2. SQL注入科普

    技术交流,安全交友联系渔夫”小白“,微信号(xz116035) SQL注入介绍 SQL注入攻击是最为常见的Web应用安全漏洞之一,国外知名安全组织OWASP针对web应用安全漏洞进行了一个排名,SQL ...

  3. 20155320 2016-2017-2《Java程序设计》第1周学习总结

    20155320 2016-2017-2<Java程序设计>第1周学习总结 教材学习内容总结 本周学习内容 浏览课本,并就每一章提出一个问题. 认真学习第一.第二章的内容. 1至18章每章 ...

  4. 20155339 2016-2017-2 《Java程序设计》第十周学习总结

    20155339 2016-2017-2 <Java程序设计>第十周学习总结 教材学习内容总结 计算机网络概述 在计算机网络中,现在命名IP地址的规定是IPv4协议,该协议规定每个IP地址 ...

  5. day 5 多态 类 静态

    1.多态 执行的时候才知道调用谁 class Dog(object): def print_self(self): print("大家好,我是来自西安的小白") class Xia ...

  6. ES6 localStorage 类库

    无意中看到的,记录下. 用到了es6语法.支持在js中写构造函数 class CovLocalDB { constructor (name) { this.LS = null this.name = ...

  7. log4net始终占用日志文件的问题

    在appender 下面加 <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

  8. iOS 上架的坑

    有3D-touch机型的坑 昨天在上线的时候遇到了一个坑,最后导致的结果是找了好几个小时,直接到半夜才能上线. 入正题: 坑是:项目运行在456上没什么问题,但是在6S以上的机型就有点击事件不响应的情 ...

  9. C#随堂

    顺序语句 上到下执行 分支语句 if    else switch() { case 1: Console.WriteLine(1); break; case 2: Console.WriteLine ...

  10. shell loop

    #!/bin/sh date i=0 while [ $i -le 30 ] do         echi $i /usr/sbin/r2/np_test_acl -f rule.txt i=$(e ...