#include
#include
#include
#include
using namespace std;
struct stu_info
{
int stu_id;
string stu_name;
bool stu_sex ; /*true 表示男 false表示女*/
int stu_score[3];/*按顺序分别为计算机,英语,数学成绩*/
};
bool comp_score_reverse(stu_info a, stu_info b)
{
if(a.stu_score[0] == b.stu_score[0] ) /*计算机成绩相同*/
{
if(a.stu_score[1] == b.stu_score[1] ) /*英语成绩相同*/
{
return a.stu_score[2] >= b.stu_score[2];
}
return a.stu_score[1] > b.stu_score[1];
}
return a.stu_score[0] > b.stu_score[0];
}
void print_stu(struct stu_info info)
{
cout <<"=================================="<
cout <<",性别="<< (info.stu_sex ? "男":"女") << endl;
cout <<"计算机成绩="<
int main(void)
{
int i;
stu_info s_info;
vector
int i_sex;
for( i=0;i<5;i++)
{
cout << "请输入第"< cin >> s_info.stu_id;
cout << "请输入第"< cin >> s_info.stu_name;
cout <<"请选择性别,1表示男,0表示女:"<< endl;
cin >>i_sex;
if( i_sex==1 )
s_info.stu_sex=true;
else
s_info.stu_sex=false;
cout << "请输入第"< cin >> s_info.stu_score[0];
cout << "请输入第"< cin >> s_info.stu_score[1];
cout << "请输入第"< cin >> s_info.stu_score[2];
v_stu_infos.push_back(s_info);
}
cout <<"============================================================"<
sort( v_stu_infos.begin(),v_stu_infos.end(),comp_score_reverse ); /*按要求进行排序*/
for_each(v_stu_infos.begin(),v_stu_infos.end(),print_stu );
}