-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI005.java
More file actions
58 lines (57 loc) · 1.64 KB
/
I005.java
File metadata and controls
58 lines (57 loc) · 1.64 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package levelB;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class I005 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int N=s.nextInt();
int nums[]=new int[N];
for(int i=0;i<N;i++){
nums[i]=s.nextInt();
}
Boolean b[]=new Boolean[N];
for(int i=0;i<N;i++){
b[i]=true;
}
for(int i=0;i<N;i++){
if(b[i]){
int num=nums[i];
while(num!=1){
if(num%2==0){
num=num/2;
for(int j=0;j<N;j++){
if(num==nums[j]){
b[j]=false;
}
}
}else{
num=(3*num+1)/2;
for(int j=0;j<N;j++){
if(num==nums[j]){
b[j]=false;
}
}
}
}
}
}
ArrayList<Integer> list=new ArrayList<>();
for(int i=0;i<N;i++){
if(b[i]){
list.add(nums[i]);
}
}
int temp[]=new int[list.size()];
for(int i=0;i<list.size();i++){
temp[i]=list.get(i);
}
Arrays.sort(temp);
for(int i=temp.length-1;i>=0;i--){
System.out.print(temp[i]);
if(i!=0){
System.out.print(" ");
}
}
}
}