题解 | #小白鼠排队#
小白鼠排队
https://www.nowcoder.com/practice/27fbaa6c7b2e419bbf4de8ba60cf372b
#include <stdio.h> struct Shu{ int age; char col[10]; }; void sort(struct Shu* s, int n){//对年龄冒泡排序,交换整个结构体 struct Shu temp; for (int i = 0; i < n; i++){ for (int j = 0; j < n - 1 - i; j++){ if (s[j].age < s[j + 1].age){ temp = s[j]; s[j] = s[j + 1]; s[j + 1] = temp; } } } } int main() { int n; while (scanf("%d", &n) != EOF) { struct Shu s[n]; for (int i = 0; i < n; i++){ scanf("%d %s", &s[i].age, s[i].col); } sort(s, n); for (int j = 0; j < n; j++){ printf("%s\n", s[j].col); } } return 0; }