forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
9.cpp
30 lines (27 loc) · 636 Bytes
/
9.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bits/stdc++.h>
using namespace std;
class Fruit {
public:
string name;
int score;
Fruit(string name, int score) {
this->name = name;
this->score = score;
}
// 정렬 기준은 '점수가 낮은 순서'
bool operator <(Fruit &other) {
return this->score < other.score;
}
};
int main(void) {
int n = 3;
Fruit fruits[] = {
Fruit("바나나", 2),
Fruit("사과", 5),
Fruit("당근", 3)
};
sort(fruits, fruits + n);
for(int i = 0; i < n; i++) {
cout << '(' << fruits[i].name << ',' << fruits[i].score << ')' << ' ';
}
}