一直循环
查看原帖
一直循环
457431
Li_wenjie楼主2021/9/8 21:40
#include<bits/stdc++.h>
using namespace std;
int n;
void dfs(int n)
{
	int p=1,q=0;
	while(n>=p)
	{
		++q;
		p*=2;
	}
	q--;
	p/=2;
	cout<<2;
	if(q>=3)
	{
		cout<<"(";
		dfs(p);
		cout<<"+";
		dfs(n-p);
		cout<<")";
	}
	else
	{
		if(q==2) cout<<"2(2)";
		if(q==0) cout<<"2(0)";
		return;
	}
	
}
int main()
{
	cin>>n;
	dfs(n);
}
2021/9/8 21:40
加载中...