题解 | #小白鼠排队#比较器只能返回true和false!
小白鼠排队
https://www.nowcoder.com/practice/27fbaa6c7b2e419bbf4de8ba60cf372b
#include <iostream> #include <string> #include <cstdio> #include <algorithm> using namespace std; struct Mouse { char color[20]; int weight; }; bool compare(Mouse m1, Mouse m2) { if (m1.weight - m2.weight >= 0) { return true; } else { return false; } } Mouse mouse[120]; int main() { int N; while (scanf("%d", &N) != EOF) { for (int i = 0; i < N; i++) { scanf("%d %s", &mouse[i].weight, mouse[i].color); } sort(mouse, mouse + N, compare); for (int i = 0; i < N; i++) { printf("%s\n", mouse[i].color); } } } // 64 位输出请用 printf("%lld")