Skip to content

Instantly share code, notes, and snippets.

@pepet96
Created December 2, 2013 00:52
Show Gist options
  • Save pepet96/7743153 to your computer and use it in GitHub Desktop.
Save pepet96/7743153 to your computer and use it in GitHub Desktop.
Simple Dishes
import java.util.Scanner;
import java.lang.Math;
public class SimpleDishes {
public static void main (String [] args) {
Scanner input = new Scanner(System.in);
int desirednum = input.nextInt();
int[] weights = new int[desirednum];
for (int i = 0; i < desirednum; i++){
weights[i] = input.nextInt();
for (int x : weights)
{
String output = " ";
double num = x;
for (int j = 14; j >= 0; j++)
{
if (num >= Math.pow(2,j))
{
num = num - Math.pow(2,j);
output = output + j + " ";
}
}
String[] r = output.split(" ");
String[] tempr = new String[r.length];
for (int l = 0; l < r.length; l++)
tempr[l] = r[r.length - l - 1];
output = " ";
for(String l : tempr)
output = output + (l + " ");
System.out.println(output.substring(0,output.length() - 1));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment