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
'PS > Baekjoon Online Judge' 카테고리의 다른 글
[백준 11006] 남욱이의 닭장 [Java] (0) | 2025.02.09 |
---|---|
[백준 03151] 합이 0 [Java] (0) | 2025.02.09 |
[백준 06118] 숨박꼭질 [Java] (0) | 2025.02.08 |
[백준 01325] 효율적인 해킹 [Java] (0) | 2025.02.08 |
[백준 01477] 휴게소 세우기 [Java] (1) | 2025.02.06 |