1005. Spell It Right (20)
2013-03-11 09:06
239 查看
考察字符串模拟数字,以及查询表
#include<iostream> #include<stack> #include<string.h> char g_WordTable[10][100] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; void OutputWordTable() { int cnt = 10; for(int i = 0; i < cnt; ++i) { printf("%s\n", g_WordTable[i]); } } int main() { //OutputWordTable();//check char input[1000]; while(scanf("%s", &input) != EOF) { int sum = 0; int len = strlen(input); for(int i = 0; i < len; ++i) sum += (input[i]-'0'); //printf("%d\n", sum);//check //get digit into stack std::stack<int> s; do { int temp = sum%10; s.push(temp); sum /= 10; }while(sum != 0); //output while(!s.empty()) { int t = s.top(); if((int)s.size() > 1) printf("%s ", g_WordTable[t]); else printf("%s\n", g_WordTable[t]); s.pop(); } } return 0; }
相关文章推荐
- PAT 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)(C++)
- PAT 1005. Spell It Right (20)
- PAT (Advanced Level) Practise - 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT 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)各位之和
- Python 实现Pat 1005. Spell It Right (20)
- PAT 1005. Spell It Right (20)
- PAT A 1005. Spell It Right (20)
- PAT-A-1005. Spell It Right (20)
- PAT甲题题解-1005. Spell It Right (20)-数位求和,水
- 1005. Spell It Right (20)
- 1005. Spell It Right (20) PAT甲级刷题
- [PAT] 1005 Spell It Right (20)