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 ...
随机推荐
- 扫描枪连接zebra打印机打印条码标签无需电脑
在一些流水线生产的现场,需要及时打印条码标签,由于现场环境和空间限制,无法摆放电脑或者通过连接电脑来打印条码标签的速度太慢, 瑞科条码特提供了一套扫描枪直接连接条码打印机,扫描枪扫描条码之后直接打印输 ...
- 老版本nginx存在安全漏洞,不停服务热升级
1.场景描述 安全部通知:nginx存在"整数溢出漏洞",经测试2017年4月21日之后的版本无问题,将openresty升级到最新版本,Nginx升级到1.13.2之后的版本. ...
- C# 面向切面编程 AOP
AOP(Aspect Oriented Programming) 面向切面编程 起源 引言 http://wayfarer.cnblogs.com/articles/241012.html AOP技 ...
- Spring Boot 为什么这么火?
没错 Spring Boot 越来越火了,而且火的超过了我的预期,作为一名行走一线的 Java 程序员,你可能在各个方面感受到了 Spring Boot 的火. Spring Boot 的火 技术社区 ...
- `http-equiv` meta 标签
来看以下有趣的代码, <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv=& ...
- JavaWeb入门——在Windows环境下安装Tomcat服务器
JavaWeb入门——在Windows环境下安装Tomcat服务器 摘要:本文主要学习如何在Windows环境中下载并安装Tomcat服务器. 下载 获取安装包 推荐去官网上下载Tomcat: htt ...
- Filter List Views 筛选器列表视图
In this lesson, you will learn how to filter a List View. Three techniques, based on different scena ...
- 基于titanic数据集预测titanic号旅客生还率
数据清洗及可视化 实验内容 数据清洗是数据分析中非常重要的一部分,也最繁琐,做好这一步需要大量的经验和耐心.这门课程中,我将和大家一起,一步步完成这项工作.大家可以从这门课程中学习数据清洗的基本思路以 ...
- 解决idea中mysql连接失败Could not create connection to database server. Attempted reconnect 3 times. Giving up.
原因是少一个参数,设置时区的. 解决方法: 加一个参数: serverTimezone=UTC jdbc:mysql://localhost:3306/SshProject?useUnicode=t ...
- redis cluster集群动态伸缩--删除主从节点
目标:从集群中剔除一组主从(5007,5008) 经过上一节增加5007,5008主从服务节点后,目前集群的情况是这样的: b3363a81c3c59d57143cd3323481259c044e66 ...