为什么死在递归了
查看原帖
为什么死在递归了
113097
百因必有AC楼主2020/8/18 18:46

RT,求助大佬

#include<bits/stdc++.h>
using namespace std;
int power_(int x){
	if(x==0)return 1;
	int t=1,cnt=0;
 	while(t<x){
        t*=2;
        cnt++;
	}
	cnt--;
	printf("2");
    if(cnt==0||cnt==2)printf("(%d)",cnt);
    if(cnt>2){
	    printf("(");
	    power_(cnt);
 	    printf(")");
   }
   x=x-t/2;
   if(x>0){
	    t=1;cnt=0;
		printf("+");
        power_(x);
   }
}
int main(){
	int n;scanf("%d",&n);
	power_(n);
	return 0;
}
2020/8/18 18:46
加载中...