P1005 Spell It Right
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的更多相关文章
- Spell checker
Spell checker Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- [solr] - spell check
solr提供了一个spell check,又叫suggestions,可以用于查询输入的自动完成功能auto-complete. 参考文献: https://cwiki.apache.org/conf ...
- poj 1035 Spell checker
Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u J ...
- Spell checker(暴力)
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20188 Accepted: 7404 De ...
- 1.7.7 Spell Checking -拼写检查
1. SpellCheck SpellCheck组件设计的目的是基于其他,相似,terms来提供内联查询建议.这些建议的依据可以是solr字段中的terms,外部可以创建文本文件, 或者其实lucen ...
- P1005 采药
P1005 采药 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2005复赛普及组第三题 描述 辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的 ...
- POJ1035——Spell checker(字符串处理)
Spell checker DescriptionYou, as a member of a development team for a new spell checking program, ar ...
- ZOJ-3380 Patchouli’s Spell Cards DP, 组合计数
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3380 题意:有m种不同的元素,每种元素都有n种不同的相位,现在假 ...
- VIM 拼写/spell check
VIM 拼写检查/spell check 一.Hunspell科普 Hunspell 作为一个拼写检查的工具,已经用在了许多开源的以及商业软件中.包括Google Chrome, Libreoffic ...
随机推荐
- docker安装redis 5.0.7并挂载外部配置和数据
环境 CentOS Linux release 7.7.1908 (Core) 拉取redis 5.0.7 镜像 docker pull redis:5.0.7 创建挂载目录 mkdir -p /ho ...
- Appium(十):元素定位(加强版)
1. 元素定位 写完上一篇元素定位的博客,发现实用性基本为零.这几天真的烦死我了,一直在找资料,还去看了一遍appium官网文档.最后结合着selenium的定位方法,测试出几种可行的元素定位方法. ...
- DiskCatalogMaker for Mac常见问题解答
DiskCatalogMaker for Mac是Mac上简单实用的磁盘管理工具,可以帮助您对多张光盘使用批量扫描模式, 生成缩略图图像选项,更加清晰,并请将其快速编目引擎与其他编目人员比较,在本篇文 ...
- Python连载57- 邮件头和主题、解析邮件
一.添加邮件头,抄送等信息 1.mail["From"]表示发送者信息,包括姓名和邮件 2.mail["To"]表示接收者信息,包括姓名和邮件地址 3.mail ...
- 【性能测评】DSP库,MDK5的AC5,AC6,IAR和Embedded Studio的三角函数性能
测试条件: 1.IAR8.30开最高等级速度优化. 2.MDK5.27正式版使用AC5开最高等级优化3,开启时间优化,测试C标准库和微库MicroLib两种. 3.MDK5.27正式版使用AC6开最高 ...
- 使用Condition
/** * ReentrantLock使用Condition对象来实现wait和notify的功能* 使用Condition时,引用的Condition对象必须从Lock实例的newCondition ...
- 计算几何 val.1
目录 计算几何 val.1 向量的点积 向量的叉积 一种奇怪的三角剖分求面积 凸包 点绕点旋转 后记 计算几何 val.1 本文并不是入门文章,供有高中数学基础的阅读 主要写一些重要的点和注意事项吧 ...
- SpringBoot集成swagger2.0
最近项目里要用到SpringBoot + swagger,查了其他小伙伴们的资料,或多或少有点问题,在此我再梳理一遍. 1.maven依赖 <parent> <groupId> ...
- How to: Initialize Business Objects with Default Property Values in Entity Framework 如何:在EF中用默认属性值初始化业务对象
When designing business classes, a common task is to ensure that a newly created business object is ...
- js-08-数组学习
一.数组语法格式 var name=[item1,item2,......] 二.数组的声明创建 var arr=new Aarray( ) //声明一个空数组对象 var arr=new Array ...