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 <bits/stdc++.h>
using namespace std;

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int pow(int i)
{
    int ans = 1;
    rep(j, i) ans *= 2;
    return ans;
}

int main()
{
    int n;
    while (cin >> n)
    {
        rep(i, 10)
        {
            if (n & 0b1 == 1)
            {
                cout << pow(i);
                if(n!=1) cout<<" ";
            }
            n = n >> 1;
        }
        cout<<endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n){

    int ans[1000];
    int p = 0;

    int m = n;
    for(int i = 2 ; i < m ; i*=2){
      if(i*2 > m)m = i;
    }

    for(int i = m ;i > 0; i/=2 ){
      if(n - i >= 0 ){
	ans[p++] = i;
	n -= i;
      }
    }
  for(int i = p - 1 ; i >= 0 ; i-- ){
    cout << ans[i] << " ";
  }
  cout << endl;

  }
  }

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	vector <int> W;
//	cut here before submit 
//	freopen("testcase.w", "r", stdin);
	string str = "";
	int i;
	for (i = 1; i <= 512; i *= 2){
		W.push_back(i);
	} // end for

	sort (W.begin(), W.end(), greater<int>() );
	int size = W.size();

	while (getline (cin, str ) ){
		vector <int> res;
		int wight = 0;
		stringstream ss(str);
		ss >> wight;
	
		for (i = 0; i < size; ++i){
			if (wight < W[i]){
				continue;
			}else if (wight == W[i]){
				res.push_back(W[i]);
				break;
			}else{	// if (wight > W[i])
				res.push_back(W[i]);
				wight -= W[i];
			} // end if
		} // end for

		sort (res.begin(), res.end() );

		for (i = 0; i < res.size(); ++i){
			cout << res[i];
			if (i != res.size() - 1){
				cout << ' ';
			} // end if
		} // end for
		cout << endl;
	} // end while

		
	return 0;
}

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

int main(){
	int n, a[] = {1,2,4,8,16,32,64,128,256,512};
	bool r[10];
	while(cin >> n){
		fill(r, r+10, false);
		for(int s = 9;0 < n && 0 <= s;s--){
			if(n >= a[s]){r[s] = true;n -= a[s];}
		}
		bool f = false;
		for(int i = 0;i < 10;i++){
			if(r[i] == true){
				if(f == true)cout << " ";
				cout << a[i];f = true;
			}
		}
		cout << endl;
	}
	return 0;
}

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()-2; i>=0; i--){
        cout<<" "<< w[i];
    }
    cout<<endl;
}
int main(){
    while(cin>>n){
        solve();
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

template <class Type>
Type power(Type X, int Y)
{
	Type Ans = 1;

	if (Y >= 0)
	{
		for (int i = 0; i < Y; i++)
		{
			Ans *= X;
		}
	}
	else
	{
		for (int i = 0; i < (-Y); i++)
		{
			Ans /= X;
		}
	}

	return Ans;
}

int main()
{
	int N;

	while (cin >> N)
	{
		for (int i = 0; i < 10; i++)
		{
			if ((N / power<int>(2, i)) % 2 == 1)
			{
				cout << power<int>(2, i) << ' ';
			}
		}

		cout << endl;
	}

	return 0;
}

C++: #include <iostream>
 
int main(){
    int a,b,c;
    int d[11];
     
     
    while(std::cin>>a){
        for(b=1;b<=10;b++){
        d[b]=0;
        }
         
        for(b=0;b<2;b++){
            if(a==b){
                d[1]=b;
            }else{
                for(c=0;c<3;c=c+2){
                    if(a==b+c){
                        d[1]=b;
                        d[2]=c;
                         
                         
                    }else{
                        for(int e=0;e<5;e=e+4){
            if(a==b+c+e){
                d[1]=b;
                d[2]=c;
                        d[3]=e;
                     
            }else{
                for(int f=0;f<9;f=f+8){
                    if(a==b+c+e+f){
                        d[1]=b;
                        d[2]=c;
                        d[3]=e;
                        d[4]=f;
                         
                    }else{
                        for(int g=0;g<17;g=g+16){
            if(a==b+c+e+f+g){
                d[1]=b;
                d[2]=c;
                        d[3]=e;
                        d[4]=f;
                        d[5]=g;
                         
            }else{
                for(int h=0;h<33;h=h+32){
                    if(a==b+c+e+f+g+h){
                        d[1]=b;
                        d[2]=c;
                        d[3]=e;
                        d[4]=f;
                        d[5]=g;
                        d[6]=h;
                         
                     
                    }else{
                        for(int i=0;i<65;i=i+64){
            if(a==b+c+e+f+g+h+i){
                d[1]=b;d[2]=c;
                        d[3]=e;
                        d[4]=f;
                        d[5]=g;
                        d[6]=h;
                        d[7]=i;
                         
            }else{
                for(int j=0;j<129;j=j+128){
                    if(a==b+c+e+f+g+h+i+j){
                        d[1]=b;
                        d[2]=c;
                        d[3]=e;
                        d[4]=f;
                        d[5]=g;
                        d[6]=h;
                        d[7]=i;
                        d[8]=j;
                         
                    }else{
                        for(int k=0;k<257;k=k+256){
            if(a==b+c+e+f+g+h+i+j+k){
                d[1]=b;
                d[2]=c;
                        d[3]=e;
                        d[4]=f;
                        d[5]=g;
                        d[6]=h;
                        d[7]=i;
                        d[8]=j;
                        d[9]=k;
                         
            }else{
                for(int l=0;l<513;l=l+512){
                    if(a==b+c+e+f+g+h+i+j+k+l){
                        d[1]=b;
                        d[2]=c;
                        d[3]=e;
                        d[4]=f;
                        d[5]=g;
                        d[6]=h;
                        d[7]=i;
                        d[8]=j;
                        d[9]=k;
                        d[10]=l;
                    }
                }
            }
             
        }
                    }
                }
            }
             
        }
                    }
                }
            }
             
        }
                    }
                }
            }
             
        }
                    }
                }
            }
             
        }
        int n=0;
        for(int m=1;m<11;m++){
        if(d[m]!=0&&n==0)
        {
            std::cout<<d[m];
            n++;
        }
        else if(d[m]!=0){
            std::cout<<" "<<d[m];
        }
    }
    std::cout<<std::endl;
    }
    return 0;
}