P1005 Spell It Right


原题

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

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805519074574336

题目的中文意思:

给定一个非负数N,你的任务是计算出N的各个位数的数字之和,并将其和用英文的形式输出出来,比如

输入:12345

输出:one five

思路:

该题的解决思路非常容易,就是的输入整数N的每一位的数字并将其相加得到sum,然后获取sum的每一位,然后将其用英文的形式输出出来。但需要注意的是在编程的时候一定要考虑sum=0的情况。

代码实现:

#include <cstdio>
#include <iostream>
#include <string>
#define maxN 101
using namespace std; int main()
{
string num[10] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
long int sum = 0;
char c;
while ((c=getchar())!='\n')
{
sum += c - '0';
}
int s[maxN], length = 0,t=sum;
while (t!=0)
{
s[length++] = t % 10;
t /= 10;
}
//针对sum=0的情况进行处理
if (sum == 0)
{
printf("zero");
return 0;
}
cout << num[s[length - 1]];
for (int i = length - 2; i >= 0; i--)
{
printf(" ");
cout << num[s[i]];
}
//system("pause");
}

P1005 Spell It Right的更多相关文章

  1. Spell checker

     Spell checker Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  2. [solr] - spell check

    solr提供了一个spell check,又叫suggestions,可以用于查询输入的自动完成功能auto-complete. 参考文献: https://cwiki.apache.org/conf ...

  3. poj 1035 Spell checker

    Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u   J ...

  4. Spell checker(暴力)

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20188   Accepted: 7404 De ...

  5. 1.7.7 Spell Checking -拼写检查

    1. SpellCheck SpellCheck组件设计的目的是基于其他,相似,terms来提供内联查询建议.这些建议的依据可以是solr字段中的terms,外部可以创建文本文件, 或者其实lucen ...

  6. P1005 采药

    P1005 采药 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2005复赛普及组第三题 描述 辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的 ...

  7. POJ1035——Spell checker(字符串处理)

    Spell checker DescriptionYou, as a member of a development team for a new spell checking program, ar ...

  8. ZOJ-3380 Patchouli’s Spell Cards DP, 组合计数

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3380 题意:有m种不同的元素,每种元素都有n种不同的相位,现在假 ...

  9. VIM 拼写/spell check

    VIM 拼写检查/spell check 一.Hunspell科普 Hunspell 作为一个拼写检查的工具,已经用在了许多开源的以及商业软件中.包括Google Chrome, Libreoffic ...

随机推荐

  1. 从一个OutOfMemoryError 学会了分析Java内存泄漏问题

    以前都是好好的,最近出现了 oom. 问题 开始是: java.lang.OutOfMemoryError: Java heap space -- :: --- [nio--exec-] c.e.p. ...

  2. Open Redirect 开放重定向

  3. Docker入门(四)——MySQL镜像中的数据库可视化

      在详细介绍这篇文章的内容前,需要说明下笔者写这篇文章的意图:笔者在现有的开发中,前后端联调的方式为Docker镜像对接,数据库使用MySQL镜像,开发环境为远程服务器,因此,笔者迫切需要一种能将远 ...

  4. tomcat的jsp页面超过65535,导致500报错

    错误信息 org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: ...

  5. idea个性化配置

    .katex { display: block; text-align: center; white-space: nowrap; } .katex-display > .katex > ...

  6. pyhton的安装,环境变量的设置,pycharm的安装下载,中文汉化和字体的设置

    1.下载pycharm https://www.7down.com/soft/336988.html 1.pycharm的汉化下载汉化包:resources_cn.jar    放到pycharm的安 ...

  7. 剑指offer笔记面试题1----赋值运算符函数

    题目:如下为类型CMyString的声明,请为该类型添加赋值运算符函数. class CMyString{ public: CMyString(char* pData = nullptr); CMyS ...

  8. JS---DOM---设置和获取---标签内容和文本内容

    设置和获取---标签内容和文本内容   总结---设置: 使用innerText主要是设置文本的, 设置标签内容, 是没有标签的效果的 innerHTML是可以设置文本内容 innerHTML主要的作 ...

  9. 使用docker部署filebeat和logstash

    想用filebeat读取项目的日志,然后发送logstash.logstash官网有相关的教程,但是docker部署的教程都太简洁了.自己折腾了半天,踩了不少坑,总算是将logstash和filebe ...

  10. qcom 8953平台 LCD亮灭屏流程及LCD知识点总结【转】

    一.LK中亮屏流程 gcdb_display_init(),进行display初始化的起始地方: oem_panel_select(),在这里去选择哪一款屏,也可以在这里添加新一款屏: dsi_pan ...