[백준]10797 문제

allnight5·2023년 6월 13일
0

백준

목록 보기
1/7
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
        int day = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] cars = new int[10];

        for (int i = 0; i < 5; i++) {
            cars[Integer.parseInt(st.nextToken())]++;
        }

        System.out.println(cars[day]);
    }
}

다른방법

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        for (int i = 0; i < 5; i++) {
            if(n == sc.nextInt()){
                count++;
            }
        }

        System.out.println(count);
    }
}
profile
공부기록하기

0개의 댓글