HDU 1279 验证角谷猜想

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1279

水题,个人认为先用数组保存再输出比较简单

#include <stdio.h>
int main()
{
	int n;
	int tem;
	int ans[100];
	int i;
	int j;

	scanf("%d",&n);
	while(n--)
	{
		i=0;
		scanf("%d",&tem);

		while (tem!=1)
		{
			if(tem%2)
				ans[i++]=tem;

			if(tem%2)
			{
				tem*=3;
				tem+=1;
			}
			else
				tem/=2;

		}
		i-=1;
		for (j=0;j<=i;j++)
		{
			if(j==0)
				printf("%d",ans[j]);
			else
				printf(" %d",ans[j]);
		}
		if(i==-1)
			printf("No number can be output !");
		printf("
");


	}
	return 0;
}


 

原文地址:https://www.cnblogs.com/frankM/p/4399547.html