본문 바로가기

Algorithm/백준

[백준] 25640번: MBTI - JAVA [자바]


 

문제


 

 

문제 풀이


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String mbti = sc.nextLine();
        //(1)
        int count =0;
        //(2)
        int friend = sc.nextInt();
        for (int i = 0; i <= friend; i++) {
            String fMbti = sc.nextLine();
            if (mbti.equals(fMbti)) count++;
			//(3)
        }

        System.out.println(count);
		//(4)
    }
}

 

  1. 진호의 mbti를 입력합니다.
  2. 진호와 같은 mbti인 친구의 수를 저장하기 위한 count 변수입니다.
  3. for문을 통해 친구 수만큼 mbti를 입력받아 진호와 같은 mbti를 입력받았을 때 count를 증가시킵니다.
  4. count를 출력합니다.

 

결과