프로그래머스 나누어 떨어지는 숫자 배열
2022. 8. 11. 13:22ㆍ코딩 공부 연습
반응형
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
vector<int> solution(vector<int> arr, int divisor) {
vector<int> answer;
for (int i =0; i< arr.size(); i++)
{
if (arr[i] % divisor == 0)
answer.push_back(arr[i]);
}
sort(answer.begin(), answer.end());
if (answer.size() == 0)
answer.push_back(-1);
return answer;
}
'코딩 공부 연습' 카테고리의 다른 글
프로그래머스 약수의 개수와 덧셈 (0) | 2022.08.12 |
---|---|
프로그래머스 폰켓몬 (0) | 2022.08.12 |
프로그래머스 카펫 (0) | 2022.08.11 |
프로그래머스 문자열 내림차순으로 배치하기 (0) | 2022.08.11 |
프로그래머스 같은 숫자는 싫어 (0) | 2022.08.11 |