시험 성적 기준 오름차순 정렬 프로그램

나무에물주기·2022년 10월 21일
0

Coding Test

목록 보기
69/77
#include <iostream>
#include <algorithm>
using namespace std;

// 시험 성적 기준 오름차순 정렬하기

class Student {
    public:
    string name;
    int score;
    Student(string name, int score) {
        this-> name = name;
        this-> score = score;
    }
    // 정렬 기준은 '점수가 작은 순서'
    bool operator < (const Student & student)const {
        return this -> score < student.score;
    }
};

int main(void)
{
    Student students[] = {
        Student("일번",90),
        Student("이번",93),
        Student("삼번",97),
        Student("사번",87),
        Student("오번",92)
    };
    sort(students, students + 5);
    for(int i = 0; i < 5; i++)
    {
        cout << students[i].name << ' ';
    }
}
profile
개인 공부를 정리함니다

0개의 댓글