pat-1005 Spell It Right

1005:计算各个数字的和,并翻译成英文。

Sample Input:
12345
Sample Output:
one five

递归实现,注意一下空格分隔的方法
#include<iostream>
using namespace std;
#include<string.h>

char number[120];

void convert(int i)
{
	switch(i)
	{
	case 0:cout<<"zero";break;
	case 1:cout<<"one";break;
	case 2:cout<<"two";break;
	case 3:cout<<"three";break;
	case 4:cout<<"four";break;
	case 5:cout<<"five";break;
	case 6:cout<<"six";break;
	case 7:cout<<"seven";break;
	case 8:cout<<"eight";break;
	case 9:cout<<"nine";break;
	}
}

void show(int n)
{
	if(n>9)
		show(n/10);

	if(n>9)
		cout<<" ";	
	convert(n%10);
}

int main()
{
	bool isfirst = true;
	cin>>number;
	int sum=0;
	for(int i=0;i<strlen(number);i++)
		sum+=number[i]-'0';
	show(sum);

}

你可能感兴趣的:(right)