//sort函数即可,需要用到函数指针 #include "stdio.h" #include "algorithm" using namespace std; struct mouse{ int weight; char color[11]; }; bool compare(mouse lhs,mouse rhs){ if(lhs.weight > rhs.weight) return true; else return false; } int main(){ int N; while(scanf("%d",&N)!=EOF){ mouse m[10000]; for (int i=0; i<N; ++i) { scanf("%d",&m[i].weight); scanf("%s",m[i].color); } sort(m,m+N,compare); for(int i=0; i<N;++i){ printf("%s\n",m[i].color); } } }