-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathugly_number.cc
63 lines (57 loc) · 1.2 KB
/
ugly_number.cc
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
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#include <utility>
#include <map>
#include <queue>
#include <sstream>
#include <cmath>
using namespace std;
template<typename T>
void PrintVec(const vector<T> &vec) {
for (auto val : vec) {
cout << val << " ";
}
cout << endl;
}
int nthUglyNumber(int n) {
unordered_map<int, int> m;
int prev = 0;
int res = 1;
--n;
for (int i = 0; i < n; ++i) {
cout << "Insert m: " << prev << " " << res << endl;
m[prev] = res;
prev = res;
res = INT_MAX;
for (int div : {2, 3, 4, 5}) {
int quo = prev / div;
if (m.count(quo)) {
res = min(res, m[quo] * div);
cout << "res: " << res << " div: " << div << " quo: " << quo << endl;
}
}
}
return res;
}
enum Color {
kBlack = 0,
kWhite = 1,
};
int main(int argc, char **argv) {
Color color = kWhite;
switch (color) {
case kBlack:
cout << "Black" << endl;
break;
case kWhite:
cout << "White" << endl;
break;
default:
cout << "default";
}
return 0;
}