#include <bits/stdc++.h>
using namespace std;
int num;
string green, teamName;
vector<string> test,team;
vector<int> prob;
struct CompareTeams{
bool operator()(const pair<int, string>& a, const pair<int, string>& b){
if(a.first != b.first){
return a.first < b.first; // prob 오름차순 정렬
}
return a.second > b.second; // team 내림차순 정렬
}
};
int main(){
cin >> green >> num;
test.push_back(green);
for(int i=0; i<num; i++){
int ret =1;
int cnt[4]={0,0,0,0};
cin >> teamName;
team.push_back(teamName);
test.push_back(teamName);
for(int i=0; i<test.size(); i++){
for(int j=0; j<test[i].size(); j++){
if(test[i][j]=='L'){
cnt[0]++;
}else if(test[i][j]=='O'){
cnt[1]++;
}else if(test[i][j]=='V'){
cnt[2]++;
}else if(test[i][j]=='E'){
cnt[3]++;
}
}
}
for(int i=0; i<4; i++){
for(int j=i+1; j<4; j++){
ret *= cnt[i]+cnt[j];
}
}
prob.push_back(ret%100);
test.pop_back(); //팀 후보명 계산한거 빼기
}
// pair<우승 확률, 팀 이름>을 저장하는 우선순위 큐
priority_queue<pair<int, string>, vector<pair<int, string>>, CompareTeams> pq;
for(int i=0; i<num; i++){
pq.push({prob[i], team[i]});
}
cout << pq.top().second << "\n";
return 0;
}
priority_queue<ElementType, ContainerType, CompareFunction> pq;
- 우선 순위 큐
- ElementType: 우선순위 큐에 저장할 원소의 데이터 타입이다. 여기서는 pair<int, string> 타입이 된다.
- ContainerType: 내부적으로 사용할 컨테이너의 타입을 지정한다. 기본값으로 vector가 사용되며, 여기서는 vector<pair<int, string>> 타입이 된다.
- CompareFunction: 원소들의 우선순위를 결정하는 비교 함수를 지정한다. 여기서는 CompareTeams 구조체로 정의한 비교 함수가 사용된다.
pq는 pair<int, string> 형태의 원소를 저장하며,
내부적으로는 vector<pair<int, string>> 컨테이너를 사용하고,
CompareTeams 구조체의 비교 함수를 이용하여 원소들의 우선순위를 결정합니다.
'코테' 카테고리의 다른 글
백준 2559번 - 수열 (0) | 2023.08.22 |
---|---|
백준 11655번 - ROT13 (0) | 2023.08.19 |
백준 1292번 - 쉽게 푸는 문제 (0) | 2023.08.14 |
백준 10988번 - 팰린드롬인지 확인하기 (0) | 2023.08.14 |
백준 2979번 - 트럭주차 (0) | 2023.08.13 |