-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpat1005.cpp
More file actions
71 lines (61 loc) · 906 Bytes
/
pat1005.cpp
File metadata and controls
71 lines (61 loc) · 906 Bytes
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
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
using namespace std;
int main()
{
int n=0,x=0;
int num [105]={0};
int key [105]={0};
int i=0;
cin>>n;
x=n;
while(x>0){
int k=0;
cin>>k;
key[i]=k;
num[k]=k;
x--;
i++;
}
for (int q=0;q<n;q++){
int _num=key[q];
int _key;
while(_num!=1){
if (_num%2!=0){
_num=_key=(_num*3+1)/2;
if(_num>100)continue;
if(num[_key]){
num[_key]=0;
}
}
else {
_num=_key=_num/2;
if(num[_key]){
num[_key]=0;
}
}
}
}
int num2 [100];
int a=0;
for(int i=0;i<n;i++){
if(num[key[i]]){
num2[a]=key[i];
a++;
}
}
for(int w=1;w<=a-1;w++){
for(int j=0;j<a-1;j++){
if(num2[j]<num2[j+1]){
int h=num2[j];
num2[j]=num2[j+1];
num2[j+1]=h;
}
}
}
for(int x=0;x<a;x++){
cout<<num2[x];
if(x!=a-1)
cout<<" ";
}
return 0;
}