작성일 :

문제 링크

25640번 - MBTI

설명

진호와 동일한 MBTI를 가진 친구의 수를 구하는 문제입니다.


접근법

진호의 MBTI와 각 친구의 MBTI를 비교합니다.

일치하는 경우 개수를 증가시키고 최종 개수를 출력합니다.



Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
using System;

class Program {
  static void Main() {
    var me = Console.ReadLine();
    var n = int.Parse(Console.ReadLine()!);
    var cnt = 0;
    for (var i = 0; i < n; i++)
      if (Console.ReadLine() == me) cnt++;
    Console.WriteLine(cnt);
  }
}

C++

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

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

  string me; cin >> me;
  int n; cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    string s; cin >> s;
    if (s == me) cnt++;
  }
  cout << cnt << "\n";

  return 0;
}