# Link
https://www.acmicpc.net/problem/2456
2456번: 나는 학급회장이다
첫째 줄에는 반의 학생들의 수 N (3 ≤ N ≤ 1,000)이 주어진다. 다음 N개의 각 줄에는 각 학생이 제출한 회장후보 3명에 대한 선호 점수가 주어지는 데, 첫 번째 점수는 후보 1번에 대한 점수이고 두
www.acmicpc.net
# Code - C++
//
// BOJ
// ver.C++
//
// Created by GGlifer
//
// Open Source
#include <iostream>
#include <algorithm>
#include <tuple>
using namespace std;
#define endl '\n'
#define len(x) (int)(x).length()
#define size(x) (int)(x).size()
#define str(x) to_string(x)
#define error logic_error("line " + str(__LINE__))
// Set up : Definitions
struct Candidate { int no, score, cnt[3+1]; };
// Set up : Global Variables
/* None */
// Set up : Functions Declaration
bool operator != (const Candidate &u, const Candidate &v);
bool operator < (const Candidate &u, const Candidate &v);
int main()
{
// Set up : I/O
ios::sync_with_stdio(false);
cin.tie(nullptr);
// Set up : Input
int N; cin >> N;
Candidate C[3+1] = {{-1}, {1}, {2}, {3}};
for (int i=0; i<N; i++) {
int s1, s2, s3;
cin >> s1 >> s2 >> s3;
// Process
C[1].cnt[s1]++; C[1].score += s1;
C[2].cnt[s2]++; C[2].score += s2;
C[3].cnt[s3]++; C[3].score += s3;
}
// Process
sort(C+1, C+(3+1), greater<>());
bool isUnique = (C[1] != C[2]);
// Control : Output
cout << ((isUnique) ? C[1].no : 0) << ' ' << C[1].score << endl;
}
// Helper Functions
bool operator != (const Candidate &u, const Candidate &v)
{
auto ut = make_tuple(u.score, u.cnt[1], u.cnt[2], u.cnt[3]);
auto vt = make_tuple(v.score, v.cnt[1], v.cnt[2], v.cnt[3]);
return ut != vt;
}
bool operator > (const Candidate &u, const Candidate &v)
{
auto ut = make_tuple(u.score, u.cnt[3], u.cnt[2], u.cnt[1]);
auto vt = make_tuple(v.score, v.cnt[3], v.cnt[2], v.cnt[1]);
return ut > vt;
}
지적, 조언, 첨언 모두 환영합니다!!!
'Problem Solving > 백준' 카테고리의 다른 글
[ Problem Solving :: 백준 ] 1526 / 가장 큰 금민수 (0) | 2021.11.21 |
---|---|
[ Problem Solving :: 백준 ] 2473 / 세 용액 (0) | 2021.11.16 |
[ Problem Solving :: 백준 ] 11558 / The Game of Death (0) | 2021.11.16 |
[ Problem Solving :: 백준 ] 2698 / 인접한 비트의 개수 (0) | 2021.11.16 |
[ Problem Solving :: 백준 ] 14606 / 피자 (Small) (0) | 2021.11.16 |