求大佬帮助,四个wa
查看原帖
求大佬帮助,四个wa
1043489
yiyezhiqiu1011楼主2023/9/2 13:14
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[30]={},l = 0;
    cin >> n;
    if (n % 2 == 1)
    {
        cout << -1;
        return 0;
    }
    for (int i = 0 ; n; i++)
    {
        a[i] = n % 2;
        n /= 2;
        ++l;
    }
    for (int i = l; i; i--)
    {
        if(a[i])
            cout << pow(2,i) << " ";
    }
    
    return 0;
}
2023/9/2 13:14
加载中...