题解 | #小白鼠排队#
小白鼠排队
https://www.nowcoder.com/practice/27fbaa6c7b2e419bbf4de8ba60cf372b
#include <iostream> #include <ratio> #include<string> #include<algorithm> using namespace std; struct rat { int weight; string color; //char color[10]; }; bool cmp(rat a,rat b) { return a.weight>b.weight;//降序排列 } int main() { int n; rat a[100]; while (cin >> n) { // 注意 while 处理多个 case //rat*a=(rat*)malloc(sizeof(n+1)); for(int i=0;i<n;i++) { //a[i].color.resize(10); cin>>a[i].weight>>a[i].color; //scanf("%d %s",&a[i].weight,&a[i].color); //cout<<a[i].weight<<" "<<a[i].color<<endl; } sort(a,a+n,cmp); for(int i=0;i<n;i++)cout<<a[i].color<<endl; } } // 64 位输出请用 printf("%lld")