문제 해결/BaekJoon

[백준] [C++] 4562번 No Brainer

WSLim_97 2022. 11. 13. 18:50
반응형

https://www.acmicpc.net/problem/4562

 

4562번: No Brainer

For each data set, there will be exactly one line of output. This line will be "MMM BRAINS" if the number of brains the zombie eats is greater than or equal to the number of brains the zombie requires to stay alive. Otherwise, the line will be "NO BRAINS".

www.acmicpc.net


코드

#include <iostream>
using namespace std;

int main() {
	int n, a, b;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (a < b) {
			cout << "NO BRAINS\n";
		}
		else {
			cout << "MMM BRAINS\n";
		}
	}
	return 0;
}

풀이

반복을 결정하는 수와 두 수를 입력받은 후 비교하여 알맞은 문구를 출력하는 문제이다.

 

첫 번째로 반복 횟수를 결정하는 n을 입력받아 for문을 활용하여 n번 반복하는 반복문을 작성한다.

 

좀비가 먹는 뇌의 수인 a와 좀비가 생존하는 데 필요한 뇌의 수인 b를 입력받는다.

 

a가 b보다 작다면 NO BRAINS를 출력하고 a가 b보다 크거나 같다면 MMM BRAINS를 출력한다.

반응형