#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
struct Student{
char name[20];
int id;
int score;
};
Student student[5]={{"Jack",112,90},{"Mike",102,87},
{"Mary",131,95},{"Tony",114,90},{"Tim",126,70}};
bool Rule(Student x,Student y){
if (x.score==y.score) return (strcmp(x.name,y.name)<0);
else return x.score>y.score;
}
int main(void){
multiset<Student,Rule> st;
for (int i=0;i<5;i++){
st.insert(student[i]);
}
multiset<Student,Rule>::iterator p;
for (p=st.begin();p!=st.end();p++){
printf("%s %d %d",p->id,p->name,p->score);
}
printf("\n");
return 0;
}
编译运行后会出现这样的情况:
看了一眼视频,是用结构体定义的规则:
请问一下为什么使用函数定义不可以,有没有更简单的一些方法?
感谢!