题解 | #小白鼠排队#
小白鼠排队
https://www.nowcoder.com/practice/27fbaa6c7b2e419bbf4de8ba60cf372b
//习题3.3 小白鼠排队 #include <cstdio> #include <algorithm> #include <iostream> using namespace std; struct Mouse{ int weight; string color; }; bool comp(Mouse x,Mouse y){ if (x.weight>=y.weight){ return true; } else{ return false; } } int main(){ int n; while(scanf("%d",&n) != EOF){ Mouse mouse1[n]; for (int i=0;i<n;i++){ cin>>mouse1[i].weight>>mouse1[i].color; } sort(mouse1,mouse1+n,comp); for (int i=0;i<n;i++){ cout<<mouse1[i].color<<endl; } } return 0; }