1005. Spell It Right (20)

考察字符串模拟数字,以及查询表

#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,ZJU)