Problem Solving/프로그래머스
나누어 떨어지는 숫자 배열
높은곳에영광
2022. 1. 16. 23:15
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> arr, int divisor) {
vector<int> answer;
vector<int> no;
no.push_back(-1);
for(int i = 0 ; i < arr.size(); i++) {
if(arr[i] % divisor == 0) answer.push_back(arr[i]);
}
sort(answer.begin(), answer.end());
return answer.empty() == true ? no : answer;
}