문제
정수 n과 정수 배열 numlist가 매개변수로 주어질 때, numlist에서 n의 배수가 아닌 수들을 제거한 배열을 return하도록 solution 함수를 완성해주세요.
솔루션
#include <string>
#include <vector>
using namespace std;
vector<int> solution(int n, vector<int> numlist) {
vector<int> answer;
for(int i = 0; i < numlist.size(); i++){
if (numlist[i] % n == 0){
answer.push_back(numlist[i]);
}
}
return answer;
}
https://school.programmers.co.kr/learn/courses/30/lessons/120905
'프로그래머스코딩테스트연습풀이 > C++' 카테고리의 다른 글
[프로그래머스/C++] 머쓱이보다 키 큰 사람 (0) | 2025.02.12 |
---|---|
[프로그래머스/C++] 배열의 유사도 (0) | 2025.02.12 |
[프로그래머스/C++] 삼각형의 완성조건 (1) (0) | 2025.02.12 |
[프로그래머스/C++] 아이스 아메리카노 (0) | 2025.02.12 |
[프로그래머스/C++] 문자열 뒤집기 (0) | 2025.02.12 |