PAT (Advanced) 1005. Spell It Right (20)
来源:互联网 发布:c语言用什么软件编写好 编辑:程序博客网 时间:2024/05/20 13:39
原题:1005. Spell It Right (20)
思路如下:
1.将英文字符串与数字对应做好表格
2.求出sum, 再分解sum, 最后根据表格输出
3.注意 0 的特殊处理
c++代码如下:
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;char a[110];char table[10][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};//打表int main(){ while(scanf("%s", a) != EOF) { int sum = 0; int len = strlen(a); for(int i = 0; i < len; i++) { sum += a[i] - '0'; } int temp[10]; int cnt = 0; if(sum == 0)// 0 的特殊处理 { temp[0] = 0; cnt = 1; } while(sum > 0) // sum 分解 { temp[cnt++] = sum % 10; sum /= 10; } for(int i = cnt - 1; i >= 0; i--) { if(i == cnt - 1) printf("%s", table[temp[i]]); else printf(" %s", table[temp[i]]); } printf("\n"); } return 0;}
阅读全文
0 0
- PAT (Advanced) 1005. Spell It Right (20)
- PAT(Advanced level) 1005. Spell It Right
- 【PAT Advanced Level】1005. Spell It Right (20)
- 【c++】PAT (Advanced Level) 1005. Spell It Right (20)
- 【PAT (Advanced Level)】1005. Spell It Right (20)
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20) 解题报告
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20)
- PAT Advanced 1005. Spell It Right (20) (C语言实现)
- 【PAT】【Advanced Level】1005. Spell It Right (20)
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- [PAT (Advanced Level) ]1005. Spell It Right解题文档
- 浙大 PAT Advanced level 1005. Spell It Right
- PAT (Advanced Level) Practise 1005 Spell It Right (20)
- PAT Advanced Level 1005:Spell It Right
- PAT-PAT (Advanced Level) Practise 1005. Spell It Right (20) (简单模拟题)【一星级】
- (PAT)1005. Spell It Right (20)
- 接口、类
- sqlite3学习笔记
- 百度云的高速下载技巧系列4---Village(原名山寨云)(安卓)
- hibernate 一级缓存(Session缓存)和持久化对象的四种状态
- UVA 624 CD
- PAT (Advanced) 1005. Spell It Right (20)
- 跨域
- 内核移植
- 打印杨辉三角
- 1008. 数组元素循环右移问题 (20)
- windows 使用
- UVA 562 Dividing coins
- java虚拟机相关
- Hadoop HA