1005. Spell It Right (20)
2017-02-15 12:49
288 查看
分析:字符串转数字。每一位数字再映射成英文。用sprintf()一下子就解决了。
代码:
代码:
#include <iostream> #include <cstdio> #include <string> #include <cstring> using namespace std; char num[15][10] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; int main() { char ch = ' '; int sum = 0; while(true) { scanf("%c", &ch); if(ch == '\n') break; sum = sum + ch - '0'; } char str[200]; sprintf(str, "%d", sum); int len = strlen(str); for(int i = 0; i < len-1; ++i) printf("%s ", num[str[i]-'0']); printf("%s\n", num[str[len-1]-'0']); return 0; }
相关文章推荐
- [PAT] 1005 Spell It Right (20)
- PAT 1005. Spell It Right (20)
- PAT甲级.1005. Spell It Right (20)
- PAT-A-1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT甲题题解-1005. Spell It Right (20)-数位求和,水
- 1005. Spell It Right (20) PAT甲级刷题
- PAT(甲级)1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20) 解题报告
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT (Advanced Level) Practise 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT甲级 1005. Spell It Right (20)
- PAT A 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)