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>
using namespace std;
int main(){
  
  int n,b;
  int a[10],i;
  while(cin >> n){
    fill_n(a,10,1024);
    b = 512;
    i=0;
    
    while(n != 0){
      if(n >= b){
	a[i] = b;
	i++;
	n -= b;
      }
      b /= 2;
    }
    sort(a,a+10);
    for(int j = 0;j < i;j++){
      if(j == i-1) cout << a[j] << endl;
      else cout << a[j] << ' ';
    }
  }

  return (0);
}

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

int x;

void func(int p2, int y)
{
	int flag = 0;
	
	if (y == 0) {
		return;
	}
	
	if (y >= p2) {
		func(p2 / 2, y - p2);
		flag = 1;
	}
	else {
		func(p2 / 2, y);
	}
	
	if (flag == 1) {
		cout << p2;
	}
	if (y != x) {
		cout << ' ';
	}
}

int main()
{
	while (cin >> x) {
		func(512, x);
		cout << endl;
	}
	
	return 0;
}

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

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

C++: #include<iostream>
#include<vector>
#include<algorithm>
 
int main()
{
    const int weight[] = {1,2,4,8,16,32,64,128,256,512};
 
    std::vector<int> answer;
 
    int n;
 
    while(std::cin >> n)
    {
        for(size_t i=0; i<10; ++i)
        {
            if(n/weight[9-i])
            {
 
                answer.push_back(weight[9-i]);
 
                n = n%weight[9-i];
            }
        }
 
        for(size_t i=0; i<answer.size()-1; ++i)
        {
            std::cout << answer[answer.size()-1-i] << ' ';
        }
 
        std::cout << answer[0] << '\n';
 
        answer.clear();
    }
 
}
Compile Error Logs:

Status
Judge: 1/1 	C++ 	CPU: 00.00 sec 	Memory: 1212 [KB] 	Length: 476 [B] 	2012-08-29 02:02 	2012-08-29 02:02
Results for testcases
							
Case #1: 	: Accepted 	- 	- 	- 	NA 	- 	NA
< | 	1 	/ 	1 	| > 	  	 : Accepted        -        -
 
Input #1 ( ) 		Output #1 ( )

Not available.

		

Not available.

Comments
 
 Under Construction.
 
Categories
 
 
Free Tags

C++: #include<cstdio>
main(){int d,a;for(;a=1,~scanf("%d",&d);)for(;a<=d;a&d&&printf((d/a>2)?"%d ":"%d\n",a),a<<=1);}

C++: //C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;
int v[30];
int main(){
  v[0]=1;
  for(int i=1;i<10;i++){
    v[i]=v[i-1]*2;
  }
  int s;
  while(cin>>s){
    vector<int> b;

    for(int i=9;i!=-1;i--){
      if(s==0)break;
      if(s>=v[i]){
        b.push_back(v[i]);
        s-=v[i];

      }
    }
    sort(b.begin(),b.end());
    for(int i=0;i<b.size()-1;i++){
      if(b[i])cout<<b[i]<<" ";
    }
    cout<<b[b.size()-1]<<endl;
    
  }

  return 0;
}

C++: #include <iostream>
#include <bitset>
#include <cmath>

int main()
{

	int weight = 0;
	while (std::cin >> weight)
	{
		std::bitset<10> bit(weight);
		int count = bit.count();

		for (int i = 0; i < 10; i++)
		{
			if (bit[i])
			{
				std::cout << std::pow(2, i);
				count--;
				if (count != 0)
				{
					std::cout << " ";
				}
			}
		}
		std::cout << std::endl;
		
	}

	return 0;
}

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

#define TRUE 1
#define FALSE 0

int use_num[10];

int get_input(void) {
    int i;
    std::cin >> i;
    if (std::cin.fail()) 
        exit(0);
    return i;
}

int power(int m, int n) {
    int acc = 1;
    for (int i = 0; i < n; i++) {
        acc *= m;
    }
    return acc;
}    

void solve(int weight) {
    for (int i = 9; i >= 0; i--) {
        if (power(2, i) > weight) {
            use_num[i] = FALSE;
        } else {
            use_num[i] = TRUE;
            weight -= power(2, i);
        }
    }
}

void output(void) {
    for (int i = 0; i <= 9; i++) {
        if (use_num[i] != FALSE) {
            std::cout << power(2, i) << ' ';
        }
    }
    std::cout << std::endl;
}

int main(void) {
    int weight;
    while (weight = get_input()) {
        solve(weight);
        output();
    }
    return 0;
}

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

using namespace std;

int main() {
	vector<int> v;
	vector<int> ans;
	int temp;
	while(1) {
		cin >> temp;
		if(cin.eof()) {
			//cout << "EOF" << endl;
			break;
		}
		v.push_back(temp);
	}
	for(auto it = v.begin(); it != v.end(); it++) {
		int weight = 512;
		for(int i=0;i<10;i++) {
			if(*it >= weight) {
				ans.push_back(weight);
				*it -= weight;
			}
			weight /= 2;
		}
		sort(ans.begin(), ans.end());
		for(auto ans_it = ans.begin(); ans_it != ans.end(); ans_it++) {
			cout << *ans_it;
			if(it - ans.begin() < 10) {
				cout << " ";
			}
		}
		cout << endl;
		ans.clear();
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  
  int n,b;
  int a[10],i;
  while(cin >> n){
    fill_n(a,10,1024);
    b = 512;
    i=0;
    
    while(n != 0){
      if(n >= b){
	a[i] = b;
	i++;
	n -= b;
      }
      if(b == 1) b--;
      else b /= 2;
    }
    sort(a,a+10);
    for(int j = 0;j < i;j++){
      if(j == i-1) cout << a[j] << endl;
      else cout << a[j] << ' ';
    }
  }

  return (0);
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){

int m,w[10];

while(cin>>m){
	int k=0;
	for(int i=0;i<10;i++)w[i]=0;
	
	for(int i=9;i>=0;i--)if(m>=pow(2,i)){w[i]=1;m-=pow(2,i);}
	
	for(int i=0;i<10;i++){
		if(w[i]==1&&k==0){cout<<pow(2,i);k=1;}
		else if(w[i]==1)cout<<" "<<pow(2,i);
	}
	cout<<endl;
	}
	return 0;
}

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

int main()
{
    int n,weight;
	int w[10]={1,2,4,8,16,32,64,128,256,512};
	while(1){
		cin >> n;
		if(cin.eof()){break;}
		int	flag[10]={0};
	
		for(int i=9 ; i>=0; i--){
			if(n>=w[i]){
				n-=w[i];
				flag[i]++;
			}
		}
		for(int i=0; i<10 ; i++){
			if(flag[i]!=0){
				cout << w[i] << " ";
			}
		}
		//cout << endl;
	}
	return 0;
}

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

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

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

int main() {
    int n;
    while(cin >> n) {
        vector<int> res;
        for(int i=0; i<10; ++i) {
            if(n & (1 << i)) {
                res.push_back(1 << i);
            }
        }
        for(int i=0; i<res.size(); ++i) {
            cout << res[i] << " \n"[i == res.size()-1] << flush;
        }
    }
}