작성일 :

문제 링크

4562번 - No Brainer

설명

좀비가 먹은 뇌의 수 X와 생존에 필요한 뇌의 수 Y가 주어질 때, X ≥ Y이면 MMM BRAINS를, 그렇지 않으면 NO BRAINS를 출력하는 문제입니다.

여러 테스트 케이스가 주어지며, 각 케이스마다 결과를 출력해야 합니다.


접근법

각 테스트 케이스에 대해 두 수를 비교하여 조건에 맞는 문자열을 출력합니다.

XY 이상이면 좀비가 생존할 수 있으므로 MMM BRAINS를, 미만이면 NO BRAINS를 출력하면 됩니다.


입력 크기가 작아 시간 복잡도는 \(O(n)\)으로 충분합니다.



Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;
using System.Linq;

class Program {
  static void Main() {
    var t = int.Parse(Console.ReadLine()!);
    foreach (var _ in Enumerable.Range(0, t)) {
      var tokens = Console.ReadLine()!.Split().Select(int.Parse).ToArray();
      var eaten = tokens[0];
      var required = tokens[1];
      Console.WriteLine(eaten >= required ? "MMM BRAINS" : "NO BRAINS");
    }
  }
}

C++

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

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

  int t; cin >> t;
  while (t--) {
    int x, y; cin >> x >> y;
    cout << (x >= y ? "MMM BRAINS" : "NO BRAINS") << "\n";
  }

  return 0;
}