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

프로그래머스 5) 나이 출력 (Lv. 0) (C++)

코테 2023. 3. 14. 00:17

전체 코드

#include <string>
#include <vector>

using namespace std;

int solution(int age) {
    int answer = 2022-age+1;
    return answer;
}

풀이

  • answer에 2022-age+1대입
  • 2022년도 기준이므로 2022에 age를 뺌
  • 태어났을때부터 1살 취급하므로 +1 더해야함
int solution(int age) {
    int answer = 2022-age+1;
    return answer;
}