Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}

		w := 512
		weights := make([]int, 10)
		for i := 9; i >= 0; i-- {
			if n >= w {
				weights[i] = w
				n -= w
			}
			w /= 2
		}

		output := []int{}
		for i := 0; i < 10; i++ {
			if weights[i] > 0 {
				output = append(output, weights[i])
			}
		}
		outputStr := fmt.Sprint(output)
		fmt.Println(outputStr[1:(len(outputStr) - 1)])
	}
}

C++: #include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

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

bool tukauka[10];//大きい順

int n,owari;
int main(){
	cin >> n;
	for(int i = 0;i < 10; i++) {
		if(n >= omosa[i])tukauka[i] = true, n -= omosa[i],owari=i;
	}
	for(int i = 0; i < 10; i++) {
		if(tukauka[9 - i]&&i==owari) {
			cout << omosa[9 - i] ;
		}else {
			cout<< omosa [ 9 - i]<<" ";
		}
	}
	cout << endl;
	return 0;
}

C++: #include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <algorithm>
#include <cctype>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);

int n;

int main(){
	while(cin>>n){
		int two=1;
		vi ans;
		for(int i=0;i<10;i++){
			two*=2;
			if(n%two){
				n-=two/2;
				ans.push_back(two/2);
			}
		}
		for(int i=0;i<ans.size()-1;i++) cout<<ans[i]<<' ';
		cout<<ans[ans.size()-1]<<endl;
	}
}

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

using namespace std;

int main(void){

	int inp,arr[100],cnt;
	int wei[]={1,2,4,8,16,32,64,128,256,512};

	while(cin>>inp){
		cnt=0;
		for(int i=9;inp!=0;i--){
			if(inp-wei[i]>=0){
				inp-=wei[i];
				arr[cnt]=wei[i];
				cnt++;
			}
		}
		for(int j=cnt-1;j>=0;j--){
			cout<<arr[j];
			if(j==0) cout<<endl;
			else cout<<" ";
		}
	}

	return 0;
}

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

int main(){
	int n;
	while(cin>>n){
		bool f=false;
		for(int i=0; i<10; i++){
			if((n & 1<<i)!=0){
				if(f) cout << " ";
				cout << (1<<i);
				f = true;
			}
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
  int a[10];
  int n;
  int x;

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

  while (cin >> n) {
    for (int i=0; i<10; i++){
      x = n & 1;
      n >>=1;
      if (x) {
        if (n) {
          cout << a[i] << " ";
        } else {
          cout << a[i] << endl;
        }
      }
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int a;
	while (cin >> a){
		bool b = false;
		if (a % 2 == 1){
			cout << '1';
			b = true;
			a -= 1;
		}
		if (a % 4 == 2){
			if (b == true) 
				cout << ' ';
			else b = true;
			cout << 2;
			a -= 2;
		}
		if (a % 8 == 4) {
			if (b == true) 
				cout << ' ';
			else b = true;
			cout << 4;
			a -= 4;
		}
		if (a % 16 == 8) {
			if (b == true) 
				cout << ' ';
			else b = true;
			cout << 8;
			a -= 8;
		}
		if (a % 32 == 16) {
			if (b == true) 
				cout << ' ';
			else b = true;
			cout << 16;
			a -= 16;
		}
		if (a % 64 == 32) {
			if (b == true) 
				cout << ' ';
			else b = true;
			cout << 32;
			a -= 32;
		}
		if (a % 128 == 64) {
			if (b == true) 
				cout << ' ';
			else b = true;
			cout << 64;
			a -= 64;
		}
		if (a % 256 == 128) {
			if (b == true) 
				cout << ' ';
			else b = true;
			cout << 128;
			a -= 128;
		}
		if (a % 512 == 256) {
			if (b == true) 
				cout << ' ';
			else b = true;
			cout << 256;
			a -= 256;
		}
		if (a % 1024 == 512) {
			if (b == true) 
				cout << ' ';
			else b = true;
			cout << 512;
			a -= 512;
		}
		cout << endl;
	}
}

C++: import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		
		while(scan.hasNext()){
			int w = scan.nextInt();
			int i = 1;
			StringBuffer sb = new StringBuffer();
			sb.setLength(0);
			while(w / 2 > 1){
				if(w % 2 == 1){
					sb.append(i).append(' ');
				}
				w /= 2;
				i = i << 1;
			}
			sb.append(i);
			String s = sb.toString().trim();
			System.out.printf("%s\n", s);
		}
	}
}

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

using namespace std;

// 問題に出てくる分銅の質量は2のn乗
// 下位のビットから1ビットずつ確認していく

int main() {
	int w;
	while (cin >> w) {
		string weights;

		// 対応するビットが1になっている確認。
		// 対応していたら値を出力する
		for (int bit = 1; bit < 1024; bit <<= 1) {
			if (bit & w) {
				weights.append(to_string(bit));
				weights.push_back(' ');
			}
		}
		// 最後のスペースを改行に置き換え
		weights.back() = '\n';
		cout << weights;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

#define PI 3.141592653

bool cross(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4){
    double a,b,c,d;
    
    a=(x3-x4)*(y1-y3)+(y3-y4)*(x3-x1);
    b=(x3-x4)*(y2-y3)+(y3-y4)*(x3-x2);
    c=(x1-x2)*(y3-y1)+(y1-y2)*(x1-x3);
    d=(x1-x2)*(y4-y1)+(y1-y2)*(x1-x4);
    
    if((c<0)^(d<0))
        return true;
    else
        return false;
}

int main(){
    int w;
    
    while(EOF!=scanf("%d",&w)){
        
        bool f = true;
        
        for(int i=0;i<=9;i++){
    
            if(w & (1 << i)){
                printf(f ? "%d" : " %d",(int)pow(2,i));
                f=false;
            }
        }
        
        printf("\n");
    }
    
    return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n;
	while( cin >> n ){
		int s = 512;
		stack<int> st;
		while( n != 0 ){
			if( n - s >= 0 ){
				st.push(s);
				n -= s;
				s /= 2;
			}
			else{
				s /= 2;
			}

		}

		while( !st.empty() ){
			cout << st.top() << " ";
			st.pop();
		}
		cout << endl;
	}
	ret 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
        int w;
        int ans[10];

        while (cin >> w) {
                int cnt = 0;
                for (int i = 1; w; i*=2) {
                        if (w % 2) {
                                ans[cnt++] = i;
                        }
                        w /= 2;
                }
                for (int i = 0; i < cnt; i++) {
                        cout << ans[i];
                        if (i < cnt - 1) {
                                cout << " ";
                        }
                }
                cout << endl;
        }

        return 0;
}