Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 우선순위큐
- DP
- 이분탐색
- 문자열
- 오블완
- 분할정복
- 티스토리챌린지
- C++
- Sort
- 배열
- 에라토스테네스의 체
- priority_queue
- N과M
- DFS
- 프로그래머스
- 백준
- Set
- 정렬
- map
- 백트래킹
- 그래프
- 알고리즘
- 다이나믹프로그래밍
- 유클리드호제법
- BFS
- 최소공배수
- 깊이우선탐색
- int
- stoi
- vector
Archives
- Today
- Total
안녕 세상아,
[프로그래머스/c++] LV1 나누어 떨어지는 숫자 배열 본문
https://school.programmers.co.kr/learn/courses/30/lessons/12910
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. arr의 값들을 divisor로 나눈 후 나누어 떨어지는 것들은 answer 벡터에 삽입
2. 값이 있든 없든 일단 sort로 정렬 실행 (algorithm 헤더 추가)
3. 만약 answer 벡터에 하나도 없으면 -1 값 삽입
#include <string>
#include <vector>
#include <algorithm>
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;
}
'프로그래머스' 카테고리의 다른 글
[프로그래머스/c++] Lv1 핸드폰 번호 가리기 (1) | 2024.07.31 |
---|---|
[프로그래머스/c++] Lv1 제일 작은 수 제거하기 (2) | 2024.07.31 |
[프로그래머스/c++] LV1 없는 숫자 더하기 (0) | 2024.07.31 |
[프로그래머스/c++] LV1 음양 더하기 (0) | 2024.07.31 |
[프로그래머스/c++] LV1 콜라츠 추측 (0) | 2024.07.30 |