[C++][백준 30791] gahui and sousenkyo 1

PublicMinsu·2023년 12월 4일

문제

접근 방법

16등부터 20등을 준다. 16등하고 경쟁할 수 있는 상대를 찾아내면 된다.

코드

#include <iostream>
using namespace std;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    int high, i = 0, low;
    cin >> high;
    for (; i < 4; ++i)
    {
        cin >> low;
        if (high - 1000 > low)
        {
            break;
        }
    }
    cout << i;
    return 0;
}

풀이

문제에서 요구하는 바로는 16등하고 1000보다 높은 차이를 내는 경우는 경쟁자라 볼 수 없다.
해당하는 인원을 제외하고 세어주면 된다.

profile
연락 : publicminsu@naver.com

0개의 댓글