1005. Spell It Right (20)
来源:互联网 发布:d3.v4.min.js下载 编辑:程序博客网 时间:2024/06/16 12:43
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:12345Sample Output:
one five
题意:给你一个字符串,让你求和,并用英文 one two... 输出和的结果
思路:将所求的和sum一位位分离开,输出对应的英文就好
(这里我傻B的写错了一个英文单词,错了好几次才发现)
#include <iostream>#include <cstdio>#include <stack>#include <cstring>using namespace std;char digit[10][10] = { "zero","one" ,"two" ,"three","four" ,"five" ,"six" ,"seven" ,"eight" ,"nine" };stack<int> ans;int main(){char str[1000];scanf("%s", str);int len = strlen(str);int sum = 0;for (int i = 0; i < len; i++)sum += str[i] - '0';do//这里用do while 是为了处理 0 的特殊情况,不然有一组数据过不来{int d = sum % 10;ans.push(d);sum /= 10;} while (sum > 0);while (!ans.empty()){int t = ans.top();if (ans.size() != 1)printf("%s ", digit[t]);elseprintf("%s\n", digit[t]);ans.pop();}return 0;}
0 0
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- C语言函数详解,linux,windows比较字符串
- 2016搜索基础21015
- cordvoa 调取本地通讯录
- tomcat7中使用websocket时如何调优
- CSS Media媒体查询
- 1005. Spell It Right (20)
- Linux学习笔记26 --DNS
- hilife技术支持网站
- 多线程下载工具axel
- linux服务配置之DNS
- Hibernate配置文件中指定MySQL数据库的编码方式
- $("#id")与document.getElementById("id")的区别
- Caffe学习系列(5):其它常用层及参数
- linux基础学习之dns服务3-1