No older revisions available
No older revisions available
~cpp
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
struct student{
string name;
int score;
student(string n, int s)
{
name=n;
score=s;
}
};
bool compare(student person1, student person2)
{
return person1.score>person2.score;
}
int main()
{
student student1("Kim", 80);
student student2("Park", 84);
student student3("Choi", 82);
vector< student > vec;
vec.push_back(student1);
vec.push_back(student2);
vec.push_back(student3);
sort(vec.begin(), vec.end(), compare);
for(vector<student>::iterator i=vec.begin();i!=vec.end();i++)
{
cout<<(*i).name<<" "<<(*i).score<<endl;
}
return 0;
}