본문 바로가기
PS/Baekjoon Online Judge

[백준 10886] 0 = not cute / 1 = cute [Java]

by kimyoungrok 2025. 2. 9.
728x90

문제

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

 


풀이

홀수인 N개의 수를 입력받아 전체 합이 N의 절반을 넘는지 확인하는 문제다.

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        // Init
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        // Input
        final int N = Integer.parseInt(br.readLine());
        int cnt = 0;

        // Solve
        for (int i = 0; i < N; ++i) {
            cnt += Integer.parseInt(br.readLine());
        }

홀수이면 "Junhee is cute!"를 아니면 "Junhee is not cute!"를 출력하자

        // Output
        System.out.println(cnt > (N >> 1) ? "Junhee is cute!" : "Junhee is not cute!");
    }
}

소스코드

보기

728x90