나의 Winding Road

BAEKJOON 10825번: 국영수 본문

개발/Algorithm

BAEKJOON 10825번: 국영수

WindingRoad 2018. 9. 4. 21:34

[2018-09-01 토요일]

* 내용: 국영수

1. 문제

2. 해결 방법


 

1. 문제


 

* 내용

- URL: https://www.acmicpc.net/problem/10825



2. 해결 방법


 

* 로직
- algorithm 있는 sort 함수 활용

- 졍렬 로직 구현

 

cout, cin 시에 시간 초과가 발생하였다. printf, scanf 변경

- 관련 참고 URL : https://www.acmicpc.net/board/view/15725

 

* 소스 코드

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
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <algorithm>
 
using namespace std;
 
struct Student {
    char name[11];
    int score1;
    int score2;
    int score3;
};
 
Student stdnt[100001];
 
bool cmp1(const Student &a, const Student &b){
    if (a.score1 == b.score1 && a.score2 != b.score2) {
        return a.score2 < b.score2;
    }
    else if (a.score1 == b.score1 && a.score2 == b.score2 && a.score3 != b.score3) {
        return a.score3 > b.score3;
    }
    else if (a.score1 == b.score1 && a.score2 == b.score2 && a.score3 == b.score3) {
        if(strcmp(a.name, b.name) < 0return true;
        else return false;
    }
    return a.score1 > b.score1;
}
 
int main() {
    int N;
    scanf("%d"&N);
 
    for (int i = 0; i < N; i++)
        scanf("%s %d %d %d", stdnt[i].name, &stdnt[i].score1, &stdnt[i].score2, &stdnt[i].score3);
 
    sort(stdnt, stdnt + N, cmp1);
 
    for (int i = 0; i < N; i++){
        printf("%s\n", stdnt[i].name);
    }
 
    return 0
}
 
cs


'개발 > Algorithm' 카테고리의 다른 글

BAEKJOON 1152번: 단어의 개수  (0) 2018.09.04
BAEKJOON 9465번: 스티커  (0) 2018.09.02
BAEKJOON 1463번: 1로 만들기  (0) 2018.08.30
로봇 청소기  (0) 2017.04.17
BAEKJOON 1260번: DFS와 BFS  (1) 2017.04.17
Comments