Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags more
Archives
Today
Total
관리 메뉴

luke

[백준] - 0 = not cute / 1 = cute (10886) (자바/Java) 본문

알고리즘문제/백준 문제(Java)

[백준] - 0 = not cute / 1 = cute (10886) (자바/Java)

luke-king 2024. 6. 17. 16:15

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

 

 

문제.


 

 

 

 

 

 

 

 

풀이.


 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        int t = 0;
        int f = 0;
        for (int i = 0; i < n; i++) {

            int person = Integer.parseInt(br.readLine());

            if (person == 0) {
                f++;
            }
            if (person == 1){
                t++;
            }

        }

        if (f < t) {
            System.out.println("Junhee is cute!");
        } else{
            System.out.println("Junhee is not cute!");
        }

    }

}

 

오늘 문제는 백준 "0 = not cute / 1 = cute" 문제다.

이번 문제는 어려움 없이 풀 수 있는 수학 문제라 생각한다.

문제 설명을 하자면 0 은 준희가 귀엽지 않다. 1 은 준희가 귀엽다 를 뜻하며 각각 투표받은 수가 큰 걸 출력하면 되는 문제다. 그럼 바로 풀이해보겠다.

 

1. f, t 변수로 0을 입력받을 경우 f를 1씩 증가시켜주고 1 입력을 받을 경우 t를 1씩 증가 시켜 준다.

 

2. 반복문이 종료되었을 때 조건식을 사용해 f와 t를 비교해 f < t 일경우 준희는 귀엽다. f > t 일경우 준희는 귀엽지 않다는 문구를 출력하면 끝이다.