80求助
查看原帖
80求助
846617
jasonhappy楼主2025/1/14 16:03

80分求助

#include <bits/stdc++.h>
using namespace std;
int d2(int n, int str[50]) {
	int i = 0;
	while (n > 0) {
		str[i++] = n % 2;
		n /= 2;
	}
	str[i] = '\0';
	return i;

}
int main() {
	int n;
	cin >> n;
	if (n % 2 == 1 || n == 0) {
		cout << -1;
		return 0;
	}
	int str[50];
	int cnt = d2(n, str);
	int i = cnt;
	for (; i >= 0; i--) {
		if (str[i] != 0) {
			cout << pow(2, i) << " ";
		}
	}
	return 0;
}
2025/1/14 16:03
加载中...