본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 15025 : Judging Moose

반응형

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

 

15025번: Judging Moose

When determining the age of a bull moose, the number of tines (sharp points), extending from the main antlers, can be used. An older bull moose tends to have more tines than a younger moose. However, just counting the number of tines can be misleading, as

www.acmicpc.net

입력과 if문을 사용해보는 문제였습니다.

 

📕 풀이방법

📔 입력 및 초기화

무스의 왼쪽 뿔, 오른쪽 뿔을 의미하는 변수 l, r을 선언 후 입력받습니다.

 

📔 정답출력

 답은 3가지로 출력됩니다.

 1. l == r 양쪽이 같으므로 짝수입니다. 아무 숫자나 * 2 해서 "Even"과 함께 출력합니다.

 2. !l && !r이면 뿔이 양쪽모두 없으므로 "Not a moose"를 출력합니다.

 3. 그 외에는 짝짝이 뿔이므로 홀수입니다. "Odd "문자열과 (l과 r의 최댓값) * 2를 출력합니다.

 


📕 Code

#include <bits/stdc++.h>
using namespace std;
int l, r;
int main(){
    cin >> l >> r;
    if(l != r) cout << "Odd " << max(l,r) * 2;
    else if(!l && !r) cout << "Not a moose";
    else cout << "Even " << l * 2;
}