题解 | #小白鼠排队#
小白鼠排队
https://www.nowcoder.com/practice/27fbaa6c7b2e419bbf4de8ba60cf372b
#include<cstdio> #include<algorithm> using namespace std; struct mice { int weight; char colour[100]; }; bool comp (mice lhs, mice rhs) { if (lhs.weight > rhs.weight) { return true; } else { return false; } } int main() { int n ; mice arr[101]; // int weight; // char colour; while (scanf("%d", &n) != EOF) { for (int idx = 0 ; idx < n ; ++idx) { scanf("%d %s\n", &arr[idx].weight, &arr[idx].colour); } sort(arr, arr + n, comp); for (int i = 0 ; i < n ; ++i) { printf("%s\n", arr[i].colour); } } }