Post

[BaekJoon] 10886번 - 0 = not cute / 1 = cute [Java][C++]

[BaekJoon] 10886번 - 0 = not cute / 1 = cute [Java][C++]

문제 링크


1. 문제 풀이


$0$ 과 $1$ 의 등장 횟수를 비교만 해주면 된다.


2. 코드


1. 풀이 [Java]

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
import java.io.*;

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

        int zeroCnt = 0;
        int oneCnt = 0;

        int N = Integer.parseInt(br.readLine());
        for (int i = 0; i < N; i++) {
            int x = Integer.parseInt(br.readLine());

            if (x == 0) {
                zeroCnt++;
            } else {
                oneCnt++;
            }
        }

        if (zeroCnt > oneCnt) {
            System.out.println("Junhee is not cute!");
        } else {
            System.out.println("Junhee is cute!");
        }
    }
}


2. 풀이 [C++]

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
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int zero = 0;
    int one = 0;

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;

        if (x == 0) {
            zero++;
        } else {
            one++;
        }
    }

    if (zero > one) {
        cout << "Junhee is not cute!";
    } else {
        cout << "Junhee is cute!";
    }
}

This post is licensed under CC BY 4.0 by the author.