No older revisions available
No older revisions available
~cpp
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct student
{
string name;
int score;
};
bool compare(student a, student b);
int main()
{
student DarkLJY;
student B;
student C;
student D;
DarkLJY.name = "juyoung";
B.name = "gogogo";
C.name = "hahaha";
D.name = "good";
DarkLJY.score = 50;
B.score = 70;
C.score = 80;
D.score =90;
vector < student > vec;
vec.push_back(DarkLJY);
vec.push_back(B);
vec.push_back(C);
vec.push_back(D);
vector < student > vec;
vec.push_back(DarkLJY);
vec.push_back(B);
sort(vec.begin(),vec.end(),compare);
for(int j=0;j<2;j++)
{
cout << vec[j].score << " ";
}
cout << endl;
return 0;
}
bool compare(student a, student b)
{
return a.score > b.score ; // 부등호의 방향에 따라 오름차순 내림차순 결정
}