Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	weight := []int{512, 256, 128, 64, 32, 16, 8, 4, 2, 1}

	for sc.Scan() {
		var wgt []int
		i, _ := strconv.Atoi(sc.Text())

		if i > 1023 {
			i = 1023
		}

		bin := fmt.Sprintf("%010b", i)

		for i := 9; i >= 0; i-- {
			if bin[i] == '1' {
				wgt = append(wgt, weight[i])
			}
		}

		for i := 0; i < len(wgt); i++ {
			if i == len(wgt)-1 {
				fmt.Printf("%d\n", wgt[i])
			} else {
				fmt.Printf("%d ", wgt[i])
			}

		}
	}

}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;

const int M = 512;

int main(void){
    for(int w; cin >> w; cout << endl)
        for(int a = 1, c = 0; a <= M; a *= 2)
            if(a & w) cout << (c ? " ":"") << a, c = 1;

    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,tmp[10]={512,256,128,64,32,16,8,4,2,1};
  while(cin >> n && n!=EOF){
    int cnt[10]={0};
    for(int i=0;i<10;i++){
      if(n-tmp[i]>=0){
    n-=tmp[i];
    cnt[i]++;
      }
      if(n==0) break;
    }
    int flg=0;
    for(int i=9;i>=0;i--){
      if(cnt[i]==1){
      if(flg==1)cout << " ";
    cout << tmp[i];
    flg=1;
      }
    }
    cout << endl;
  }
}

C++: #include<iostream>
using namespace std;

int main(void)
{
	int n;
	while(cin >> n)
	{
		int e = 1;
		bool first_output = true;
		for(int i=0; i<=10; i++)
		{
			if( (n & e) == e )
			{
				if(first_output)
				{
					cout << e;
					first_output = false;
				}
				else
					cout << " " << e;
			}
			e *= 2;
		}
		cout << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

int n;

int main()
{
  while(cin >> n){
    for(int i=0; n; n>>=1, i++) if(n & 1) cout << (1 << i) << (n >> 1 ? " " : "\n");
  }

  return 0;
}

C++: #include<iostream>

using namespace std;

void conv(int n, int a[10])
{
	for(int i=0;i<10;i++)
	{
		a[i]=n%2;
		n=n/2;
	}
}

int pow(int x, int n)
{
	int ans=1;
	for(int i=0;i<n;i++)
	{
		ans*=x;
	}
	return ans;
}

int main(void)
{
	int w;
	while(cin>>w)
	{
		int a[10];
		conv(w,a);
		for(int i=0;i<10;i++)
		{
			if(a[i]==1)
			{
				cout<<pow(2,i)<<" ";
			}
		}
		cout<<endl;
	}
}

C++: #include<iostream>
#include<vector>

using namespace std;
const int V[10] = {512, 256, 128, 64, 32, 16, 8, 4, 2, 1};
int n;

void solve(){
    vector<int> w;
    for(int i=0; i<10; i++){
        int f = n/V[i];
        if(f!=0){
            n -= V[i];
            w.push_back(V[i]);
        }
    }
    for(int i=w.size()-1; i>=0; i--){
        cout<< w[i]<<" ";
    }
    cout<<endl;
}
int main(){
    while(cin>>n){
        solve();
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
using namespace std;

int main(){
	int a;
	while(cin>>a){
		int w[10]={},j=0;
		while(a){
			rep(i,0,10){
				if(pow(2,i)<=a && a<pow(2,i+1)){
					a-=pow(2,i);
					w[i]++;
				}
			}
		}
		rep(i,0,10){
			if(w[i]){
				if(j==0){
					cout<<pow(2,i);
					j++;
				}else cout<<" "<<pow(2,i);
			}
		}
		cout<<endl;
	}
}

C++: #include <iostream>

using namespace std;

void k(int a, int* b)
{
	bool flag[10] = {};
	bool isFirst = true;

	for (int i = 9; i >= 0; i--)
	{
		if (a - b[i] >= 0)
		{
			a = a - b[i];
			flag[i] = true;
		}
	}

	for (int i = 0; i < 10; i++)
	{
		if (flag[i])
		{
			if (isFirst)
			{
				isFirst = false;
			}
			else
			{
				cout << " ";
			}
			cout << b[i];
		}
	}
	cout << endl;
}
int main()
{
	int a;
	int weights[10];

	weights[0] = 1;
	for (int i = 1; i < 10; i++)
	{
		weights[i] = weights[i - 1] * 2;
	}

	while (cin >> a)
	{
		k(a, begin(weights));
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int h[10]={1,2,4,8,16,32,64,128,256,512};
  int o,hk;
  while(cin>>o){
    hk = true;
    int w[1023][10]={0};
    for(int i=0;i<10;i++){
      if(h[i]>o) break;
      for(int j=o;j>=0;j--){
	if(j==0) w[h[i]][0] = h[i];
	else if(w[j][0]!=0&&j+h[i]<=o){
	  for(int n=0;n<10;n++){
	    if(w[j][n]==0){
	      for(int m=0;m<n;m++) w[j+h[i]][m] = w[j][m];
	      w[j+h[i]][n] = h[i];
	      break;
	    }
	  }
	}
	if(j==0) w[h[i]][0] = h[i];
      }
    }
      for(int i=0;i<10;i++){
	if(w[o][i]==0) break;
	if(hk!=true) cout << ' ';
	cout << w[o][i];
	if(hk==true) hk = false;
      }
      cout << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

class STACK{

public:
	STACK(){
		index = 0;
	}
	void push(int data){
		array[index++] = data;
	}
	int pop(){
		index--;
		return array[index];
	}
	bool isEmpty(){
		return index == 0;
	}
	int getIndex(){
		return index;
	}

private:
	int array[10];
	int index;
};

int main(){
	int w;
	STACK stack;

	while(scanf("%d",&w) != EOF){
		for(int i = 256; i>= 1; i /= 2){
			if(w>=i){
				stack.push(i);
				w -= i;
			}
		}

		while(!stack.isEmpty()){
				if(stack.getIndex() == 1){
					printf("%d\n",stack.pop());
				}else{
					printf("%d ",stack.pop());
				}
		}
	}

	return 0;
}

C++: #include<iostream>
#include<vector>

int bun[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };

int main(){

	int n;
	while (std::cin >> n){

		std::vector<int> res;

		for (int i = 9; i >= 0; i--){
			if (n >= bun[i]){
				res.push_back(bun[i]);
				n -= bun[i];
			}
		}

		for (int i = res.size() - 1; i >= 0; i--){
			if (i == 0)std::cout << res[i] << std::endl;
			else std::cout << res[i] << " ";
		}
	}

	return 0;
}