개수 세기

황상익·2023년 12월 18일
0

백준

목록 보기
13/15
import java.util.Scanner;

public class 개수새기 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int cnt = 0;
        int[] arr = new int[N];

        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }
        int V = sc.nextInt();
        for (int i = 0; i < arr.length; i++) {
            if (V == arr[i]) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}


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

public class 개수세기_1 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());

        int[] num = new int[N];
        for (int i = 0; i < N; i++) {
            num[i] = Integer.parseInt(st.nextToken());
        }

        int V = Integer.parseInt(br.readLine());
        int cnt = 0;
        for (int i = 0; i < num.length; i++) {
            if (V == num[i]){
                cnt ++;
            }
        }

        System.out.println(cnt);
        br.close();
    }
}
profile
개발자를 향해 가는 중입니다~! 항상 겸손

0개의 댓글