当前位置:网站首页>Leetcode-6126: designing a food scoring system
Leetcode-6126: designing a food scoring system
2022-07-25 20:38:00 【Chrysanthemum headed bat】
leetcode-6126: Design food scoring system
subject
Problem solving
Method 1 : Orderly map+ Orderly set
According to the way of cooking , You can get dishes and corresponding scores , Choose the one with the highest score .
1. use first unordered_map<string,XXXX> according to The way of cooking , Get the corresponding Dishes and scores .
2. So how to get score The biggest , You can use order map( Red and black trees ), With score As key, Sort from large to small .
So there is map<int,XXXX,greater<int>>, So you can get the corresponding dishes by scoring
3. In order to ensure that the dishes are dictionary order , So use ordered sets , Sort from small to large ,set<string>
therefore unordered_map<string,map<int,set<string>,greater<int>>> map;
It can be based on The way of cooking ----> Maximum score ----> The one with the smallest dictionary order
class FoodRatings {
public:
map<string,int> foodRating;// variety of dishes ---> score
map<string,string> foodClass;// variety of dishes --> The way of cooking
unordered_map<string,map<int,set<string>,greater<int>>> map;// The way of cooking ----> score ( From big to small )----> variety of dishes
FoodRatings(vector<string>& foods, vector<string>& cuisines, vector<int>& ratings) {
for(int i=0;i<foods.size();i++){
foodRating[foods[i]]=ratings[i];
foodClass[foods[i]]=cuisines[i];
map[cuisines[i]][ratings[i]].insert(foods[i]);
}
}
void changeRating(string food, int newRating) {
// Delete the corresponding old dish score from the set
map[foodClass[food]][foodRating[food]].erase(food);
if(map[foodClass[food]][foodRating[food]].empty()){
// If the corresponding score map It's empty , Then delete the map
map[foodClass[food]].erase(foodRating[food]);
}
// Record the score of new dishes
foodRating[food]=newRating;
map[foodClass[food]][newRating].insert(food);
}
string highestRated(string cuisine) {
return *(map[cuisine].begin()->second.begin());
}
};
边栏推荐
- How much memory does bitmap occupy in the development of IM instant messaging?
- Step num problem
- Google guava is just a brother. What is the real king of caching? (glory Collection Edition)
- Interpretation of filter execution sequence source code in sprigboot
- Follow up of Arlo's thinking
- Technology cloud report: what is the difference between zero trust and SASE? The answer is not really important
- Recommended books | essentials of industrial digital transformation: methods and Practice
- [tensorrt] trtexec tool to engine
- [today in history] June 29: SGI and MIPS merged; Microsoft acquires PowerPoint developer; News corporation sells MySpace
- [advanced mathematics] [8] differential equation
猜你喜欢

Remote monitoring solution of intelligent electronic boundary stake Nature Reserve

【高等数学】【3】微分中值定理与导数的应用

【高等数学】【4】不定积分
![[onnx] export pytorch model to onnx format: support multi parameter and dynamic input](/img/bd/e9a1d3a2c9343b75dbae5c7e18a87b.png)
[onnx] export pytorch model to onnx format: support multi parameter and dynamic input

Solution to oom exceptions caused by improper use of multithreading in production environment (supreme Collection Edition)

Has baozi ever played in the multi merchant system?

程序的编译和运行
![[today in history] July 7: release of C; Chrome OS came out;](/img/a6/3170080268a836f2e0973916d737dc.png)
[today in history] July 7: release of C; Chrome OS came out; "Legend of swordsman" issued
![[today in history] July 8: PostgreSQL release; SUSE acquires the largest service provider of k8s; Activision Blizzard merger](/img/14/f2b68dbe4e6a9b8d89ed9ff38f5e11.png)
[today in history] July 8: PostgreSQL release; SUSE acquires the largest service provider of k8s; Activision Blizzard merger

Brush questions with binary tree (4)
随机推荐
preprocessor directives
[tensorrt] trtexec tool to engine
Embedded development: embedded foundation -- threads and tasks
tga文件格式(波形声音文件格式)
C language file reading and writing
[advanced drawing of single cell] 07. Display of KEGG enrichment results
[leetcode] 28. Implement strstr ()
The uniapp project starts with an error binding Node is not a valid Win32 Application ultimate solution
Struct, enum type and union
Web crawler principle analysis "suggestions collection"
"Chain" connects infinite possibilities: digital asset chain, wonderful coming soon!
[today in history] June 29: SGI and MIPS merged; Microsoft acquires PowerPoint developer; News corporation sells MySpace
Success factors of software R & D effectiveness measurement
Array of sword finger offer question bank summary (I) (C language version)
Arrow parquet
文件操作详解
【高等数学】【8】微分方程
process.env
Apache Mina framework "suggestions collection"
test