~cpp
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct student{
string name;
int score;
student()
{
}
student(string aName, int aScore) // ?? !!
{
name = aName;
score = aScore;
}
};
bool comp_score(student a, student b);
bool comp_name(student a, student b);
void main()
{
student students[5] = {
student("",94),
student("",95),
student("",93),
student("",87),
student("",98),
};
vector<student> vector1;
for(int i=0; i<5; i++)
vector1.push_back(students[i]);
sort(vector1.begin(), vector1.end(), comp_score);
for(i=0; i<5; i++)
cout << vector1[i].score << endl ;
sort(vector1.begin(), vector1.end(), comp_name);
for(vector<student>::iterator j=vector1.begin(); j<vector1.end(); j++)
cout << (*j).name << endl ;
}
bool comp_score(student a, student b)
{
return a.score < b.score;
}
bool comp_name(student a, student b)
{
return a.name < b.name;
}