为什么 巴士分???!!!
查看原帖
为什么 巴士分???!!!
1398547
Song_Mu_yun楼主2024/9/11 22:43
#include <bits/stdc++.h>
using namespace std;
int opo[10001];
int main()
{
	int u;
	cin>>u;
	int o=u;
	int h=0;
	while(u)
	{
		opo[h]=u;
		h++;
		if(u%2==0)
		{
			u/=2;
		}
		else if(u%2!=0)
		{
			u=u*3+1;
		}
		if(u==1)
		{
			break;
		}
	}
	cout<<1<<" ";
	for(int i=h-1;i>=0;i--)
	{
		cout<<opo[i]<<" ";
	}

	return 0;
}
2024/9/11 22:43
加载中...