提交时间:2024-08-20 12:46:21

运行 ID: 168650

#include<iostream> using namespace std; void judge( int n ) { if(n==1){ cout<<2<<"("<<0<<")"; } else if(n==2){ cout<<2; } else if(n==0){ return ; } else{ int i,j; for(i=1;i<=14;i++){ int sum = 2; for(j=2;j<=i;j++){ sum*=2; } if((n-sum)>=0&&(n-sum)<sum) { n=n-sum; if(i==2) { cout<<2<<"("<<i<<")"; if(n!=0) cout<<"+"; } else if(i == 1) { cout<<2; if(n!=0) cout<<"+"; } else { cout<<2<<"("; judge(i); cout<<")"; if(n!=0) cout<<"+"; } judge(n); } } } } int main() { int a; scanf("%d",&a); judge(a); return 0; }