您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: