-
Notifications
You must be signed in to change notification settings - Fork 0
/
TowerProblem.java
36 lines (33 loc) · 1023 Bytes
/
TowerProblem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.*;
import java.io.*;
public class TowerProblem{
public static void main(String[] args){
Scanner ob = new Scanner(System.in);
int[] input = new int[8];
for(int i = 0; i<8 ; i++){
input[i] = ob.nextInt();
}
for(int i = 0 ; i<6; i++){
for(int j = i+1; j<6; j++){
for(int k = j+1; k<6; k++){
// boolean[] b = new boolean[6];
if(input[i]+input[j]+input[k] == input[6]){
boolean[] b = new boolean[6];
b[i] = b[j] = b[k] = true;
int[] sorted = {input[i],input[j],input[k]};
Arrays.sort(sorted);
System.out.print(sorted[2]+" "+sorted[1]+" "+sorted[0]+" ");
for(int t = 0, u =0; t<6 ; t++){
//system.out.println(input[t]);
if(!b[t]){
sorted[u++] = input[t];
}
}
Arrays.sort(sorted);
System.out.print(sorted[2]+" "+sorted[1]+" "+sorted[0]+" ");
}
}
}
}
}
}