通过代码:
#include <bits/stdc++.h> using namespace std; int n; string str; string to2D(int _n) { if(_n == 0) return "0"; else if(_n == 2) return "2"; int _mol; string _c_str, _d_str; while(_n) { _mol = _n % 2, _n /= 2; _d_str += _mol + '0'; } #define yum _d_str.size() - i - 1 for(int i = 0; i < _d_str.size(); i ++) if(_d_str.at(yum) == '1') _c_str += "2(" + to2D(yum) + ")+"; _c_str.resize(_c_str.size() - 1); int _pos = _c_str.find("2(2(0))"); while(_pos != -1) { _c_str.replace(_pos,string("2(2(0))").size(), "2"); _pos = _c_str.find("2(2(0))"); } return _c_str; } int main() { scanf("%d", &n); str = to2D(n); printf("%s", str.c_str()); return 0; }
1208:2的幂次方表示
最新推荐文章于 2024-05-31 17:52:13 发布