Algorithm/Sorting
Baekjoon 10825 국영수
GirlFriend_Yerin
2019. 8. 23. 13:05
Link https://www.acmicpc.net/problem/10825
소스결과 6688 KB / 140 ms
출처 Baekjoon
언어 C++ 17
분류 정렬
설명
도현이네 반 학생을 주어진 조건대로 정렬하자
STL 연습겸, 정렬 알고리즘을 연습하기 좋은문제
구조체 배열 / vector sort 사용하기 , Quick, Merge Sort 연습용도로는 괜찮은 문제다.
알고리즘이라 할만한 내용도 크게 없다.
소스코드
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
struct Student
{
string name;
int kor;
int eng;
int mat;
bool operator<(const Student& s) {
if (kor < s.kor)
return false;
else if (kor == s.kor)
{
if (eng > s.eng)
return false;
else if (eng == s.eng)
{
if (mat < s.mat)
return false;
else if (mat == s.mat)
{
if (name > s.name)
return false;
}
}
}
return true;
}
};
int main()
{
int n;
cin >> n;
vector<Student> student(n);
for (int i = 0; i < n; i++)
cin >> student[i].name >> student[i].kor >> student[i].eng >> student[i].mat;
sort(student.begin(), student.end());
for (int i = 0; i < n; i++)
printf("%s\n", student[i].name.c_str());
return 0;
}