有点忘记strcmp函数了
最小年龄的3个职工
http://www.nowcoder.com/questionTerminal/a9fa482eb05149cdbad88689e3cb5f66
return ( strcmp(a.name, b.name)<0 )? true : false;
记忆
#include<bits/stdc++.h> using namespace std; int n; struct node { int num; char name[15]; int age; }; bool cmp( node a , node b) { if( a.age!=b.age ) { return a.age<b.age; } else { if( a.num!=b.num ) { return a.num<b.num; } else { //有点不记得了 return ( strcmp(a.name, b.name)<0 )? true : false; } } } int main() { while( ~scanf("%d",&n) ) { vector<node> solve; int loop=n; while( n-- ) { node temp; scanf("%d %s %d",&temp.num, temp.name, &temp.age); solve.push_back(temp); } sort(solve.begin(), solve.end(), cmp ); loop=min( loop, 3); for(int i=0; i<loop; ++i) { printf("%d %s %d\n", solve[i].num, solve[i].name, solve[i].age); } } return 0; }