문제

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; 하면 시간초과 나옴

Posted by pi92

블로그 이미지
pi92

공지사항

Yesterday
Today
Total

달력

 « |  » 2025.7
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 31

최근에 올라온 글

최근에 달린 댓글

글 보관함