Login
Password
Forgot password?
Compiler
Language
C++
C
Python
#include
#include
#include
#include
#include
// студент typedef std::tuple
student; // список студентов typedef std::vector
students; // добавляем студентов void fill(students& s) { std::vector
> names = { {"Иванов", "Иван"}, {"Петров", "Петр"}, {"Сидоров", "Сидор"} }; std::for_each(names.begin(), names.end(), [&](const std::pair
& item) { s.push_back( student(item.first, item.second, rand(), rand(), rand() ) ); } ); } int main() { students st; fill(st); // сортируем. // первые три - студенты с меньшим средним балом. std::sort(st.begin(), st.end(), [](const student& s1, const student& s2) { return ( std::get<2>(s1)+std::get<3>(s1)+std::get<4>(s1) < std::get<2>(s2)+std::get<3>(s2)+std::get<4>(s2) ); } ); std::for_each(st.begin(), st.end(), [&](const student& st) { std::cout << std::get<0>(st) << " " << std::get<2>(st) << " " << std::get<3>(st) << " " << std::get<4>(st) << " " << std::endl; } ); return 0; }
Hide/Show
Сидоров 596516649 1649760492 719885386 Петров 424238335 1957747793 1714636915 Иванов 1681692777 846930886 1804289383
exit code: 0, execution time: 0.1012