'commit'
This commit is contained in:
25
TangDou/CSP-J/J2_2020/1_ErJinZhi.cpp
Normal file
25
TangDou/CSP-J/J2_2020/1_ErJinZhi.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 32;
|
||||
int a[N], al;
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
if (n % 2) {
|
||||
puts("-1");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// 将x拆分成二进制形式,用数组装起来
|
||||
while (n) {
|
||||
a[++al] = n % 2;
|
||||
n /= 2;
|
||||
}
|
||||
|
||||
for (int i = al; i; i--) // 由高位到低位
|
||||
if (a[i]) printf("%d ", 1 << (i - 1));
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user