1005. Spell It Right (20)
2015-11-21 19:27
288 查看
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:
Sample Output:
one five
------------------------华丽的分割线-----------------------
分析:可以使用一个栈来输出结果
代码:
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:
12345
Sample Output:
one five
------------------------华丽的分割线-----------------------
分析:可以使用一个栈来输出结果
代码:
#include<cstdio> #include<cstring> #include<stack> using namespace std; const char digit[10][6] = {"zero","one","two","three","four","five","six","seven","eight","nine"}; stack<int> result; char input[102]; int main(void) { scanf("%s",input); int sum = 0; int length = strlen(input); for(int i = 0;i<length;++i) { sum+=input[i] - '0'; } do { result.push(sum%10); sum /= 10; }while(sum>0); do { printf("%s",digit[result.top()]); result.pop(); if(!result.empty()) printf(" "); }while(!result.empty()); // system("pause"); return 0; }
相关文章推荐
- 爬爬爬之路:UI(九) UITableView(一) MVC模式M层的应用
- 安卓图表引擎AChartEngine(六) - 框架源码结构图
- android5.0+(NavigationView)
- iOS笔记之单例模式的理解
- SQL Server中的聚合函数和模式匹配
- dubbo+zookeeper集群配置
- 单链表基本操作
- 最小权顶点覆盖问题
- http Basics
- 手脱ASProtect v1.23 RC1(无Stolen Code)
- Android studio用的几个插件
- 安卓图表引擎AChartEngine(五) - Dataset和Render参数介绍
- 机器学习算法代码汇总(Python&R)
- 【转载常见问题】Refreshing Gradle Project
- C++编程学习50个经典网站 强力推荐
- java多线程三种方式区别,java多线程,线程同步方式,线程同步加锁的方法,wait与sleep区别
- hdoj--2094--产生冠军(集合函数)
- 协议测试设备
- [TwistedFate]UITableView表视图
- 0024网络爬虫的基本原理(二)