[C++][백준 10886] 0 = not cute / 1 = cute

PublicMinsu·2025년 9월 3일

문제

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

접근 방법

1이 과반을 넘는지 확인하면 됩니다.

코드

#include <iostream>
using namespace std;

int N, sum;

int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> N;

    for (int i = 0, j; i < N; ++i)
    {
        cin >> j;
        sum += j;
    }

    cout << ((sum * 2 > N) ? "Junhee is cute!" : "Junhee is not cute!");
    return 0;
}

풀이

1의 개수를 세는 것이 곧 1을 더하는 것과 똑같기에 1을 모두 더해줍니다.
2를 곱했을 때 N보다 크면 과반이라는 뜻이므로 과반을 넘은지 여부로 출력을 결정해 주면 됩니다.

profile
연락 : publicminsu@naver.com

0개의 댓글