-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiv479_D. Divide by three, multiply by two.cpp
More file actions
55 lines (50 loc) · 1.09 KB
/
Div479_D. Divide by three, multiply by two.cpp
File metadata and controls
55 lines (50 loc) · 1.09 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
//
// main.cpp
// Div479_D. Divide by three, multiply by two
//
// Created by 신지식 on 12/01/2019.
// Copyright © 2019 Shin Ji Sik. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct node{
long long num;
long long change;
int count;
};
bool cmp(const node &u, const node &v){
if(u.count > v.count)
return true;
else if(u.count == v.count)
return u.num < v.num;
return false;
}
int main(int argc, const char * argv[]) {
int n;
cin >> n;
vector<node> v;
long long t;
for(int i = 0; i < n; i++){
cin >> t;
v.push_back({t, t, 0});
}
bool check = false;
while(check != true){
int cc = 0;
for(int i = 0; i < n; i++){
if(v[i].change % 3 == 0){
v[i].count++;
cc = 1;
v[i].change /= 3;
}
}
if(cc == 0)
check = true;
}
sort(v.begin(), v.end(), cmp);
for(int i = 0; i < n; i++)
cout << v[i].num << " ";
cout << "\n";
}