-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path406.cpp
78 lines (61 loc) · 1.43 KB
/
406.cpp
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
72
73
74
75
76
77
78
#include<vector>
#include<algorithm>
using namespace std;
struct node
{
node(){};
node(int h, int k) : h(h), k(k) {};
int h;
int k;
bool operator()(struct node n)
{
return h > n.h || (h == n.h && k < n.k);
}
};
bool cmp(node x, node y)
{
return x.h > y.h || (x.h == y.h && x.k < y.k);
};
class Solution {
public:
vector<vector<int> > reconstructQueue(vector<vector<int> >& people) {
vector<node> v;
vector<node> vOut;
vector<vector<int> > vRet;
/*
vector<int> vec;
vec.push_back(0);
vec.insert(vec.begin(), 1);
*/
for(int i = 0; i < people.size(); ++i)
{
node n(people[i][0], people[i][1]);
v.push_back(n);
}
sort(v.begin(), v.end(), cmp);
for(int i = 0; i < v.size(); ++i)
{
vOut.insert(v.begin(), v[i]);
//vOut.insert(v.begin() + v[i].k, v[i]);
}
for(int i = 0; i < vOut.size(); ++i)
{
vector<int> tmp;
tmp.push_back(vOut[i].h);
tmp.push_back(vOut[i].k);
vRet.push_back(tmp);
}
return vRet;
}
};
int main()
{
Solution s;
vector<int> v1;
v1.push_back(7);
v1.push_back(0);
vector<vector<int> > v;
v.push_back(v1);
s.reconstructQueue(v);
return 0;
}