-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rotto.java
50 lines (38 loc) · 1.23 KB
/
Rotto.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Rotto {
static int n;
static int[] array;
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static StringBuilder sb;
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while(true){
sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine());
n= Integer.parseInt(st.nextToken());
if(n==0) break;
array = new int[n];
for (int i=0; i<n; i++){
array[i] = Integer.parseInt(st.nextToken());
}
rotto(0,0);
bw.write('\n');
}
bw.close();
}
public static void rotto(int depth, int startIndex)throws IOException{
if(depth==6){
bw.write(sb.toString());
bw.write('\n');
return;
}
for(int i=startIndex; i<n; i++){
int length = sb.length();
sb.append(array[i]).append(' ');
rotto(depth+1,i+1);
sb.delete(length,sb.length());
}
}
}