Post

[BaekJoon] 10797번 - 10부제 [Java][C++]

[BaekJoon] 10797번 - 10부제 [Java][C++]

문제 링크


1. 문제 풀이


날짜의 일의 자리 숫자와 자동차 번호의 일의 자리 숫자가 일치하면 자동차 10부제를 위반한 차량이다.


2. 코드


1. 풀이 [Java]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.io.*;
import java.util.*;

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

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

        int cnt = 0;
        st = new StringTokenizer(br.readLine());
        while (st.hasMoreTokens()) {
            int x = Integer.parseInt(st.nextToken());

            if (n == x) cnt++;
        }

        System.out.println(cnt);
    }
}


2. 풀이 [C++]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
using namespace std;

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

    int n;
    cin >> n;

    vector<int> v(5);
    for (int& x : v) cin >> x;

    int cnt = 0;
    for (int x : v) {
        if (n == x) cnt++;
    }

    cout << cnt;
}

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