알고리즘/2020 Goricon 문제풀이

[2020 Goricon] BOJ 20113 긴급 회의

4Legs 2020. 12. 5. 20:16

문제 링크 : www.acmicpc.net/problem/20113

 

20113번: 긴급 회의

투표 결과 1번 플레이어가 1표, 3번 플레이어가 2표, 4번 플레이어가 1표를 받아 3번 플레이어가 퇴출된다.

www.acmicpc.net

단순 구현 문제이다.

동일 득표자가 2명 이상일 시 아무도 퇴출되지 않음에 유의하자.

 

[코드]

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
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
 
using namespace std;
typedef pair<intint> p;
 
int n, votes[101];        //0: 무투표
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(NULL);
 
    int input, target, maxvote = 0;
    cin >> n;
 
    for (int i = 0; i < n; i++) {
        cin >> input;
        votes[input]++;
    }
 
    bool no_one = false;
    for (int i = 1; i <= n; i++) {
        if (votes[i] == maxvote) no_one = true;
        if (votes[i] > maxvote) {
            no_one = false;
            maxvote = votes[i];
            target = i;
        }
    }
 
    if (no_one) printf("skipped\n");
    else printf("%d\n", target);
 
    return 0;
}
cs