Created
December 2, 2013 00:52
-
-
Save pepet96/7743153 to your computer and use it in GitHub Desktop.
Simple Dishes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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