1005. Spell It Right (20)
来源:互联网 发布:java split用法 空格 编辑:程序博客网 时间:2024/06/07 06:56
1005. Spell It Right (20)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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
提交代码
题解: 纯模拟即可, 用字符串存储, 然递归求解即可.
#include <cstdio>#include <cstring>const int N = 110;char S[][6] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};void print(int x) {if (x < 10)printf("%s", S[x]);else {print(x / 10);printf(" %s", S[x % 10]);}}int main() {char str[N];scanf("%s", str);int sum = 0;for (int i = 0; str[i]; ++i)sum += str[i] - '0';print(sum);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)
- 正则表达式
- Java如何保留两位小数
- iOS开发零基础教程之证书、描述文件、App ID的解释
- leetcode 035 Search Insert Position
- 数据库入门
- 1005. Spell It Right (20)
- WinCE Socket的陷阱
- ViewController的加载的生命周期
- POJ 3566 Building for UN (无脑构造 水题)
- 网络封包过滤之分层服务提供者(LSP)
- 二元数组中的指针
- 【Qt】QTableView表格滚动条样式实现QStyleSheet
- webstorm 快捷键
- 多对一单向关联关系理解与实践