문제
정수 리스트 num_list가 주어질 때, 마지막 원소가 그전 원소보다 크면 마지막 원소에서 그전 원소를 뺀 값을 마지막 원소가 그전 원소보다 크지 않다면 마지막 원소를 두 배한 값을 추가하여 return하도록 solution 함수를 완성해주세요.
솔루션
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> num_list) {
vector<int> answer;
answer = num_list;
if(num_list[num_list.size()-1] > num_list[num_list.size()-2]){
answer.push_back(num_list[num_list.size()-1] - num_list[num_list.size()-2]);
}
else{
answer.push_back(num_list[num_list.size()-1]*2);
}
return answer;
}
https://school.programmers.co.kr/learn/courses/30/lessons/181927
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
'프로그래머스코딩테스트연습풀이 > C++' 카테고리의 다른 글
[프로그래머스/C++] 문자 리스트를 문자열로 변환하기 (0) | 2025.02.18 |
---|---|
[프로그래머스/C++] 원소들의 곱과 합 (0) | 2025.02.18 |
[프로그래머스/C++] 수 조작하기 1 (0) | 2025.02.17 |
[프로그래머스/C++] 수 조작하기 2 (0) | 2025.02.17 |
[프로그래머스/C++] 카운트 업 (0) | 2025.02.17 |