-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoLocPhat.java
More file actions
39 lines (37 loc) · 1.12 KB
/
SoLocPhat.java
File metadata and controls
39 lines (37 loc) · 1.12 KB
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
package Code_Ptit;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Queue;
public class SoLocPhat {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
Queue<String> q = new LinkedList<>();
q.add("6");
q.add("8");
ArrayList<String> al = new ArrayList<>();
while(true){
String tmp = q.peek();
al.add(tmp);
q.remove();
if(tmp.length() <= n-1){
q.add(tmp + "6");
q.add(tmp + "8");
}
else break;
}
while(q.size() > 0){
al.add(q.peek());
q.remove();
}
System.out.println(al.size());
for(int i = al.size() - 1; i >= 0; i--){
System.out.print(al.get(i) + " ");
}
System.out.println();
}
}
}