2023. 11. 1. 10:39 자기개발/코딩테스트
C++ (코딩테스트) - 국영수(백준) : 정렬
문제
https://www.acmicpc.net/problem/10825
10825번: 국영수
첫째 줄에 도현이네 반의 학생의 수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 한 줄에 하나씩 각 학생의 이름, 국어, 영어, 수학 점수가 공백으로 구분해 주어진다. 점수는 1보다 크거나 같고, 1
www.acmicpc.net
내가 푼 코드
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
using namespace std;
struct student
{
string name;
int kor;
int eng;
int math;
};
bool compare(const student& a, const student& b)
{
if (a.kor != b.kor)
return a.kor > b.kor;
if (a.eng != b.eng)
return a.eng < b.eng;
if (a.math != b.math)
return a.math > b.math;
return a.name < b.name;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int N;
vector<student> v;
cin >> N;
v.resize(N);
for (int i = 0; i < N; i++)
{
student temp;
cin >> temp.name >> temp.kor >> temp.eng >> temp.math;
v[i] = temp;
}
sort(v.begin(), v.end(), compare);
for (int i = 0; i < N; i++)
{
cout << v[i].name << '\n';
}
return 0;
}
마지막
cout << v[i].name << '\n'; 을 cout << v[i].name << endl; 하면 시간초과 나옴
'자기개발 > 코딩테스트' 카테고리의 다른 글
C++ (코딩테스트) - Yonsei TOTO(백준) 우선순위 큐 사용 (0) | 2023.11.28 |
---|---|
C++ (코딩테스트) - 컵라면(백준) 우선순위 큐 사용 (0) | 2023.11.27 |
C++ (코딩테스트) - 넷이 놀기(백준) (0) | 2023.09.22 |
C++ (코딩테스트) - 코코넛 그 두 번째 이야기(백준) (0) | 2023.09.22 |
C++ (코딩테스트) - 스텍(백준) (0) | 2023.09.20 |