프로그래머스 코딩테스트 입문(C++)

프로그래머스 4) 숫자 비교하기 (Lv. 0) (C++)

코테 2023. 3. 14. 00:16

전체 코드

#include <string>
#include <vector>

using namespace std;

int solution(int num1, int num2) {
    int answer = 0;
    if(num1==num2)
        answer=1;
    else
        answer=-1;
    return answer;
}

풀이

  • num1과 num2가 같은 경우 answer을 1로 설정
  • 그렇지 않은 경우(num1과 num2가 다른 경우) answer을 -1으로 설정
if(num1==num2)
    answer=1;
else
    answer=-1;