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

简介: 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 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 <iostream>
#include <vector>
using namespace std;
int main()
{
    string words;
    cin >> words;
    int sum = 0;
    for (char it : words)
    {
        sum += atoi(&it);
    }
    string hash[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    string res = to_string(sum);
    cout << hash[res[0] - '0'];
    for (int i = 1; i < res.size(); i++)
    {
        int num = res[i] - '0';
        cout << " " << hash[num];
    }
    return 0;
}
目录
相关文章
|
API
Angular 2.x折腾记 :(3)初步了解服务及使用
不探究高深理论,只探究实际使用,有更好的写法或者经验请指出; 有些暂时没涉及到的知识我可能会顺着例子解释;
239 0
|
Android开发 数据格式 XML
MaterialWidgetLibrary 学习
studio项目地址:https://github.com/keithellis/MaterialWidget 修改后的eclipse项目地址: 修改后的eclipse项目 Demo地址: activity_main.
812 0
|
Java
第九章 Libgdx内存管理
Android游戏开发群:290051794 Libgdx游戏开发框架交流群:261954621   游戏是使用资源较多的应用。图像和音效会占用大量的内存。
869 0
|
2天前
|
云安全 人工智能 安全
AI被攻击怎么办?
阿里云提供 AI 全栈安全能力,其中对网络攻击的主动识别、智能阻断与快速响应构成其核心防线,依托原生安全防护为客户筑牢免疫屏障。
|
12天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
6天前
|
安全 Java Android开发
深度解析 Android 崩溃捕获原理及从崩溃到归因的闭环实践
崩溃堆栈全是 a.b.c?Native 错误查不到行号?本文详解 Android 崩溃采集全链路原理,教你如何把“天书”变“说明书”。RUM SDK 已支持一键接入。
473 199

热门文章

最新文章