-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2353.cpp
More file actions
37 lines (29 loc) · 1.03 KB
/
2353.cpp
File metadata and controls
37 lines (29 loc) · 1.03 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
#include<iostream>
#include<vector>
#include<unordered_map>
#include<set>
class FoodRatings {
private:
std::unordered_map<std::string, std::pair<std::string, int>> foodInfo;
std::unordered_map<std::string, std::set<std::pair<int, std::string>>> cuisineFoods;
public:
FoodRatings(std::vector<std::string>& foods, std::vector<std::string>& cuisines, std::vector<int>& ratings) {
for (int i = 0; i < foods.size(); ++i) {
foodInfo[foods[i]] = { cuisines[i], ratings[i] };
cuisineFoods[cuisines[i]].insert({ -ratings[i], foods[i] });
}
}
void changeRating(std::string food, int newRating) {
auto [cuisine, prevRating] = foodInfo[food];
cuisineFoods[cuisine].erase({ -prevRating, food });
cuisineFoods[cuisine].insert({ -newRating, food });
foodInfo[food].second = newRating;
}
std::string highestRated(std::string cuisine) {
auto best = cuisineFoods[cuisine].begin();
return best->second;
}
};
int main() {
std::cin.get();
}