Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
168684 | A班石婧予 | 幂次方 | C++ | 通过 | 100 | 0 MS | 260 KB | 1027 | 2024-08-20 13:11:07 |
#include <bits/stdc++.h> #include <stdio.h> #define BASE 2 void convert(int n, int e) { int digit, quotient; if(e == 0) { if(n == 0) ; else if( n == 1) printf("2(0)"); else if(n == 2) printf("2"); else { convert(n / BASE, e+1); digit = n % BASE; if(digit) { printf("+"); convert(digit, e); } } } else { quotient = n / BASE; digit = n % BASE; if(quotient > 0) { convert(quotient, e+1); if(digit) printf("+"); } if(digit) { if(e == 1) printf("2"); else { printf("2("); convert(e, 0); printf(")"); } } } } int main(void) { int n; scanf("%d", &n); convert(n, 0); printf("\n"); return 0; }