https://www.acmicpc.net/problem/8979
8979번: 올림픽
입력의 첫 줄은 국가의 수 N(1 ≤ N ≤ 1,000)과 등수를 알고 싶은 국가 K(1 ≤ K ≤ N)가 빈칸을 사이에 두고 주어진다. 각 국가는 1부터 N 사이의 정수로 표현된다. 이후 N개의 각 줄에는 차례대로 각
www.acmicpc.net
생각해 보기
- 조건은 총 4가지다.
- 금메달, 은메달, 동메달, 모두 같음
- sort함수를 이용해 정렬을 한 뒤 등수를 매기자
- 등수를 변경하는 것과 현재 n을 확인하는 순서를 조심하자
코드
더보기
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
using namespace std;
bool cus_sort(tuple<int,int,int,int> &a , tuple<int,int,int,int> &b){
if(get<1>(a)==get<1>(b)){
if(get<2>(a)==get<2>(b))
return get<3>(a)>get<3>(b);
return get<2>(a)>get<2>(b);
}
return get<1>(a)>get<1>(b);
}
int N, K;
int g,s,b,n;
vector<tuple<int, int, int, int> > arr;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>N>>K;
for(int i=0;i<N;++i){
cin>>n>>g>>s>>b;
arr.push_back({n,g,s,b});
}
sort(arr.begin(),arr.end(),cus_sort);
int rank=1;
for(int i=0;i<N;++i){
if(!(i&&get<1>(arr[i])==get<1>(arr[i-1])&&get<2>(arr[i])==get<2>(arr[i-1])&&get<3>(arr[i])==get<3>(arr[i-1])))
rank=i+1;
if(get<0>(arr[i])==K){
cout<<rank<<'\n';
break;
}
}
return 0;
}

728x90
'알고리즘 > 백준 문제' 카테고리의 다른 글
| 20125 - 쿠키의 신체 측정 (0) | 2023.02.27 |
|---|---|
| 25757 - 임스와 함께하는 미니게임 (0) | 2023.02.24 |
| 9655 - 돌 게임 (0) | 2023.02.23 |
| 10431 - 줄 세우기 (0) | 2023.02.23 |
| 5073 - 삼각형과 세 변 (0) | 2023.02.22 |
댓글