1일1알

백준 11637번 인기 투표 C++ 본문

알고리즘

백준 11637번 인기 투표 C++

영춘권의달인 2023. 5. 19. 13:15

https://www.acmicpc.net/problem/11637

 

11637번: 인기 투표

각 테스트 케이스는 첫 번째 줄부터 순서대로 출력된다. 최다 득표자가 과반수 득표를 했을경우에는 "majority winner R", 절반 이하의 득표를 하였을 경우엔 "minority winner R"가 되며, 최다 득표자가 없

www.acmicpc.net

 

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>

using namespace std;
using int64 = long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int maxVal = 0;
        int sum = 0;
        int maxIdx = -1;
        bool same = false;
        for (int i = 1; i <= n; i++) {
            int val;
            cin >> val;
            sum += val;
            if (val == maxVal) {
                same = true;
            }
            else if (val > maxVal) {
                maxIdx = i;
                maxVal = val;
                same = false;
            }
        }
        if (same) cout << "no winner\n";
        else {
            sum -= maxVal;
            if (sum < maxVal) cout << "majority winner " << maxIdx << "\n";
            else cout << "minority winner " << maxIdx << "\n";
        }
    }
}

'알고리즘' 카테고리의 다른 글

백준 16938번 캠프 준비 C++  (0) 2023.05.21
백준 5002번 도어맨 C++  (0) 2023.05.20
백준 16509번 장군 C++  (0) 2023.05.16
백준 17413번 단어 뒤집기 C++  (0) 2023.05.15
백준 17085번 십자가 2개 놓기 C++  (1) 2023.05.14