Created
August 9, 2013 17:13
-
-
Save boxysean/6195342 to your computer and use it in GitHub Desktop.
Lotto UVa 441
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
package homework04; | |
import java.util.Arrays; | |
import java.util.Scanner; | |
import java.util.Stack; | |
// 441 Lotto | |
public class Main00441 { | |
public static void main(String[] args) throws Exception { | |
Scanner in = new Scanner(System.in); | |
int n[] = new int[15]; | |
boolean first = true; | |
while (in.hasNextInt()) { | |
int N = in.nextInt(); | |
if (N == 0) { | |
break; | |
} | |
// Only put a blank space between cases | |
if (first) { | |
first = false; | |
} else { | |
System.out.println(); | |
} | |
for (int i = 0; i < N; i++) { | |
n[i] = in.nextInt(); | |
} | |
// Sort numbers in ascending order | |
Arrays.sort(n, 0, N); | |
int numbers[] = new int[N]; | |
System.arraycopy(n, 0, numbers, 0, N); | |
// Then switch it so they are in descending order | |
for (int i = 0; i < N/2; i++) { | |
int t = n[i]; | |
n[i] = n[N-i-1]; | |
n[N-i-1] = t; | |
} | |
for (int mask = (1 << N)-1; mask >= 0; mask--) { | |
if (Integer.bitCount(mask) == 6) { | |
// String bs = Integer.toBinaryString(mask); | |
// while (bs.length() != N) { | |
// bs = "0" + bs; | |
// } | |
// System.out.print(bs); | |
StringBuilder sb = new StringBuilder(); | |
for (int i = N-1; i >= 0; i--) { | |
if (((1 << i) & mask) != 0) { | |
sb.append(n[i]).append(' '); | |
} | |
} | |
System.out.println(sb.toString().trim()); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment