求助
查看原帖
求助
229957
Wu_while楼主2021/1/3 16:10
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int n;
struct st
{
	int num;
	bool b=1;
};
void f(int n)
{
	if(n==0)
	{
		cout<<"0";
		return;
	}
	int cnt=-1;
	stack<st> s;
	st t;
	while(!s.empty())
		s.pop();
	while(n>0)
	{
		cnt++;
		if(n&1)
		{
			t.num=cnt;
			if(n>>1==0)
				t.b=0;
			s.push(t);
		}	
		n>>=1;
	}
	while(!s.empty())
	{
		t=s.top();
		s.pop();
		if(t.num==1)
			cout<<2;
		else
		{	
			cout<<"2(";
			f(t.num);
			cout<<")";
		}
		if(!t.b)
			cout<<'+';
	}
}
int main()
{
	cin>>n;
	f(n);
	return 0;
}

怎么控制'+'的输出?

2021/1/3 16:10
加载中...