九度 oj 题目1095:2的幂次方

来源:互联网 发布:店宝宝软件可靠吗 编辑:程序博客网 时间:2024/06/05 05:48

http://ac.jobdu.com/problem.php?pid=1095


code 转自:

http://blog.csdn.net/wdkirchhoff/article/details/42246349


#include <stdio.h>#include <cmath>void solve(int n){     int cnt = 0;    while(pow(2,cnt)<=n) cnt++;    cnt--;    if(cnt==0){         printf("2(0)");      }else if(cnt==1) {         printf("2");      }else{         printf("2(");              solve(cnt);         printf(")");     }         int num_r = n - (int) pow(2,cnt);    if(num_r){         printf("+");          solve(num_r);     }  }  int main(){    int n;    while(scanf("%d",&n)!=EOF){         solve(n);          printf("\n");     }       }  


0 0
原创粉丝点击