File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ public class Main {
5+
6+ public static void main (String [] args ) throws Exception {
7+ // write your code here
8+ Scanner scn = new Scanner (System .in );
9+ int n = scn .nextInt ();
10+ int [] arr = new int [n ];
11+ for (int i = 0 ;i < n ;i ++){
12+ arr [i ] = scn .nextInt ();
13+ }
14+ int count = (int )Math .pow (2 ,n );
15+ for (int i =0 ;i <count ;i ++){
16+ int bin = dtob (i );
17+ int div = (int )Math .pow (10 ,n -1 );
18+ for (int j =0 ; j <arr .length ; j ++){
19+ int q = bin /div ;
20+ int r = bin %div ;
21+ if (q ==0 ){
22+ System .out .print ("- " );
23+ }else {
24+ System .out .print (arr [j ] + " " );
25+ }
26+ bin =r ;
27+ div /=10 ;
28+ }
29+ System .out .println ();
30+ }
31+
32+ }
33+ public static int dtob (int n ){
34+ int ans = 0 ;
35+ int power = 1 ;
36+
37+ while (n != 0 ){
38+ int rem = n %2 ;
39+ n = n /2 ;
40+ ans = ans +(rem *power );
41+ power *= 10 ;
42+ }
43+ return ans ;
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments