Skip to content

Instantly share code, notes, and snippets.

@Dobiasd
Last active September 11, 2020 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dobiasd/ca9963ecafa786a18bd5990414fd9a59 to your computer and use it in GitHub Desktop.
Save Dobiasd/ca9963ecafa786a18bd5990414fd9a59 to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
struct cat
{
double cuteness() const
{
return softness_ * temperature_ * roundness_ * fur_amount_ - size_;
}
std::string name_;
double softness_;
double temperature_;
double size_;
double roundness_;
double fur_amount_;
};
int main()
{
std::vector<cat> cats = {
{"Tigger", 5, 5, 5, 5, 5},
{"Simba", 2, 9, 9, 2, 7},
{"Muffin", 9, 4, 2, 8, 6},
{"Garfield", 6, 5, 7, 9, 5}};
auto cutest_cat = *std::max_element(cats.begin(), cats.end(),
[](const cat& c1, const cat& c2) {
return c1.cuteness() < c2.cuteness();
});
std::cout << cutest_cat.name_ <<
" is happy and sleepy. *purr* *purr* *purr*" << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment