自定义排序准则,自定义数据类型
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef struct
{
string name;
int num;
int punish;
}Node;
bool cmp(Node a,Node b)
{
if(a.num!=b.num)return a.num>b.num;
else if(a.num==b.num && a.punish!=b.punish)return a.punish<b.punish;
else if(a.num==b.num && a.punish==b.punish)return a.name<b.name;
}
int main()
{
int n;
Node L;
vector<Node> coll;
while(cin>>n&&n)
{
for(int i=0;i<n;++i)
{
cin>>L.name>>L.num>>L.punish;
coll.push_back(L);
}
sort(coll.begin(),coll.end(),cmp);
for(int i=0;i<n;++i)
cout<<coll[i].name<<endl;
coll.clear();
}
return 0;
}
补充:软件开发 , C++ ,