#include\x20 #include\x20 #include\x20 using\x20namespace\x20std;

struct\x20Student\x20{ \x20\x20string\x20name; \x20\x20int\x20math; \x20\x20int\x20chinese; \x20\x20int\x20english; \x20\x20int\x20geography; \x20\x20int\x20total; };

bool\x20compareTotal(const\x20Student&\x20s1,\x20const\x20Student&\x20s2)\x20{ \x20\x20return\x20s1.total\x20>\x20s2.total; }

int\x20main()\x20{ \x20\x20int\x20N; \x20\x20cin\x20>>\x20N; \x20\x20vector\x20students(N); \x20\x20for\x20(int\x20i\x20=\x200;\x20i\x20<\x20N;\x20i++)\x20{ \x20\x20\x20\x20cin\x20>>\x20students[i].name; \x20\x20\x20\x20cin\x20>>\x20students[i].math; \x20\x20\x20\x20cin\x20>>\x20students[i].chinese; \x20\x20\x20\x20cin\x20>>\x20students[i].english; \x20\x20\x20\x20cin\x20>>\x20students[i].geography; \x20\x20\x20\x20students[i].total\x20=\x20students[i].math\x20+\x20students[i].chinese\x20+\x20students[i].english\x20+\x20students[i].geography; \x20\x20} \x20\x20 \x20\x20sort(students.begin(),\x20students.end(),\x20compareTotal); \x20\x20 \x20\x20for\x20(int\x20i\x20=\x200;\x20i\x20<\x20N;\x20i++)\x20{ \x20\x20\x20\x20cout\x20<<\x20students[i].total\x20<<\x20endl; \x20\x20} \x20\x20cout\x20<<\x20students[0].name\x20<<\x20endl; \x20\x20cout\x20<<\x20students[0].math\x20<<\x20"\x20"\x20<<\x20students[N-1].geography\x20<<\x20endl; \x20\x20 \x20\x20return\x200; }

C++ 编程:寻找班级学习小状元

原文地址: https://www.cveoy.top/t/topic/pFxz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录