首页 > 其他 > 详细

1002. 写出这个数 (20)

时间:2015-01-19 06:45:23      阅读:272      评论:0      收藏:0      [点我收藏+]
把一个数串各个数位上的数加起来,然后用给定格式输出,这个输出很有讲究,一个大数从高位向地位输出。
代码如下:
#include<iostream>
using namespace std;

char str[110];
int res=0,flag=0;
char output[15][5] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};

void out(int x)
{
	if(x>9)
	{
		out(x/10);
	}
	if(flag)
	{
		cout<<" ";
	}
	else
	{
		flag=1;
	}
	cout<<output[x%10];
}

int main()
{
	res=0;
	flag=0;
	gets(str);
	for(int i=0;str[i];i++)
	{
		res+=str[i]-‘0‘;
	}
	out(res);
	return 0;
}

  其中大数从高位向低位输出的方法如下:

void out(int x)
{
	if(x>9)
	{
		out(x/10);
	}
	if(flag)
	{
		cout<<" ";
	}
	else
	{
		flag=1;
	}
	cout<<output[x%10];
}

  

1002. 写出这个数 (20)

原文:http://www.cnblogs.com/CHLL55/p/4232865.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!