-
Notifications
You must be signed in to change notification settings - Fork 1
/
1005.c
58 lines (56 loc) · 1.22 KB
/
1005.c
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
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
int compare_ints(const void* a, const void* b){
int arg1 = *(const int*)a;
int arg2 = *(const int*)b;
if (arg1 < arg2) return 1;
if (arg1 > arg2) return -1;
return 0;
}
int main(){
int n,arr[101]={0},i,j=1,h;
scanf("%d",&n);
if(n==1){
scanf("%d",&n);
printf("%d",n);
return 0;
}
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
}
qsort(arr,n,sizeof(int),compare_ints);
for(i=0;i<n;i++){
if(arr[i]!=0){
int temp=arr[i];
while(temp!=1){
if(temp%2==0){
temp/=2;
}
else{
temp=(3*temp+1)/2;
// temp=3*temp+1;
}
for(h=0;h<n;h++){
if(arr[h]==temp){
arr[h]=0;
}
}
}
}
}
for(i=0;i<n;i++){
if(arr[i]!=0){
if(j==1){
printf("%d",arr[i]);
j=0;
}
else{
printf(" %d",arr[i]);
}
}
}
return 0;
}