-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1333.cpp
56 lines (46 loc) · 1.36 KB
/
1333.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
static bool cmp(const vector<int>& v1, const vector<int>& v2) {
return v1[1] == v2[1] ? v1[0] > v2[0] : v1[1] > v2[1];
}
class Solution {
public:
vector<int> filterRestaurants(vector<vector<int>>& restaurant, int veganFriendly, int maxPrice, int maxDistance) {
int n=restaurant.size();
vector<vector<int>>result;
if(veganFriendly==1)
{
for(int i=0;i<n;i++)
{
if(restaurant[i][2]==1)
{
if(restaurant[i][3]<=maxPrice)
{
if(restaurant[i][4]<=maxDistance)
{
result.push_back(restaurant[i]);
}
}
}
}
}
if(veganFriendly==0)
{
for(int i=0;i<n;i++)
{
if(restaurant[i][3]<=maxPrice)
{
if(restaurant[i][4]<=maxDistance)
{
result.push_back(restaurant[i]);
}
}
}
}
sort(result.begin(),result.end(),cmp) ;
vector<int>ids;
for(int i=0;i<result.size();i++)
{
ids.push_back(result[i][0]);
}
return ids;
}
};