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. iOS----------证书的制作

    https://developer.umeng.com/docs/66632/detail/66748#createappid Certificates-> 卫生许可证 identifiers ...

  2. flutter_boot android和flutter源码阅读记录

    版本号0.1.54 看源码之前,我先去看下官方文档,对于其源码的设计说明,文中所说的原生都是指android 看完官方文档的说明,我有以下几个疑问 第一个:容器是怎么设计的? 第二个:native和f ...

  3. python数据挖掘第三篇-垃圾短信文本分类

    数据挖掘第三篇-文本分类 文本分类总体上包括8个步骤.数据探索分析->数据抽取->文本预处理->分词->去除停用词->文本向量化表示->分类器->模型评估.重 ...

  4. CentOS 上配置 lua 的服务器环境(enet)

    安装 lua & luarocket 安装依赖 $ yum install gcc gcc-c++ kernel-devel $ yum install readline-dev $ yum ...

  5. Shell命令的执行优先级

    Shell内置命令.外部命令.别名.函数.保留关键字的优先级 在Shell中,有5种可调用的东西:别名(alias).函数(function).shell保留关键字.shell内置命令.外部命令. 如 ...

  6. JavaWeb学习——Servlet相关的接口和类

    JavaWeb学习——Servlet相关的接口和类 摘要:本文主要学习了Servlet相关的接口和类. Servlet的接口和类 三种方式 实现Servlet有三种方式: 实现javax.servle ...

  7. 【JS档案揭秘】第三集 深入最底层探秘原型链

    关于这部分我看过大量的文章,数不胜数,包括阮一峰的继承三部曲,还有各种慕课的视频教程,网上无数继承方法的对比.也对很多概念存在长期错误的理解.今天做一个正确的总结,用来给原型链和继承这块知识画上句号, ...

  8. Ubuntu 18.04安装MySQL

    安装 MySQL 服务端 sudo apt-get install mysql-server 等待安装完成. 检查 mysql 服务状态 servive mysql status 登录 mysql 客 ...

  9. 30(1).原型聚类---k-means

    原型聚类prototype-based clustering假设聚类结构能通过一组原型刻画. 常见的原型聚类有: k均值算法k-means 学习向量量化算法Learning Vector Quanti ...

  10. C语言程序设计100例之(15):除法算式

    例15   除法算式 问题描述 输入正整数n(2≤n≤68),按从小到大输出所有形如abcde/fghi=n的表达式.其中a~i为1~9的一个排列. 输入格式 每行为一个正整数n (n <= 1 ...