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
- 에라토스테네스의 체
- map
- Set
- 우선순위큐
- int
- 다이나믹프로그래밍
- 프로그래머스
- 문자열
- stoi
- BFS
- 유클리드호제법
- priority_queue
- 오블완
- 티스토리챌린지
- 이분탐색
- DP
- vector
- N과M
- Sort
- 알고리즘
- 배열
- 분할정복
- 최소공배수
- DFS
- 깊이우선탐색
- 그래프
- C++
- 백트래킹
- 정렬
- 백준
Archives
- Today
- Total
안녕 세상아,
[프로그래머스/c++] Lv1 두 개 뽑아서 더하기 본문
https://school.programmers.co.kr/learn/courses/30/lessons/68644
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. for문을 돌려서 모든 수를 다 더한다.
2. 중복된 수를 지운다 ( vector erase, unique 사용)
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> numbers) {
vector<int> answer;
for (int i = 0; i < numbers.size(); i++) {
for (int j = i + 1; j < numbers.size(); j++) {
int cnt = 0;
cnt = numbers[i] + numbers[j];
answer.push_back(cnt);
}
}
sort(answer.begin(), answer.end());
answer.erase(unique(answer.begin(), answer.end()), answer.end());
return answer;
}
기존에 했던 방식인 erase, unique 사용했는데 알고보니 set 사용해도 된다고 하더라고요..? set 특징 중 하나가 중복 수 제거니까! 근데 사용법 잊어버려서 다시 공부하고 해야디...화이팅!
https://hello-world-cpp.tistory.com/29
[c++/algorithm] std::set,std::map
set, map의 차이는 set은 key값만 저장하고 map은 key값과 value를 저장한다. set과 map 둘 다 중복을 허용하지 않는다. 또한, 둘 다 컨테이너 내부에서 오름차순으로 정렬 된다. std::set 컨테이너 template
hello-world-cpp.tistory.com
'프로그래머스' 카테고리의 다른 글
[프로그래머스/c++] Lv1 푸드 파이트 대회 (0) | 2024.09.14 |
---|---|
[프로그래머스/c++] Lv1 두 개 뽑아서 더하기 (0) | 2024.09.14 |
[프로그래머스/c++] Lv1 K번째수 (0) | 2024.09.13 |
[프로그래머스/c++] Lv1 숫자 문자열과 영단어 (0) | 2024.09.13 |
[프로그래머스/c++] Lv1 가장 가까운 같은 글자 (0) | 2024.08.31 |