◈ 문제 설명
◈ 문제 설명 링크
코딩테스트 연습 - 두 개 뽑아서 더하기 | 프로그래머스 스쿨
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
◈ 작성 코드
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> numbers)
{
vector<int> answer;
vector<int> ace;
sort(numbers.begin(),numbers.end());
for(int i = 0; i < numbers.size() - 1; i++)
{
for(int j = i + 1; j < numbers.size(); j++)
{
int a = numbers[i] + numbers[j];
ace.push_back(a);
}
}
sort(ace.begin(), ace.end());
int t = 0;
int c = -1;
while(t < ace.size())
{
if(ace[t] != c)
{
answer.push_back(ace[t]);
c = ace[t];
}
t++;
}
return answer;
}
'[프로그래머스 C++] > LEVEL 1' 카테고리의 다른 글
[프로그래머스 C++] K번째수 (0) | 2025.03.31 |
---|---|
[프로그래머스 C++] 모의고사 (0) | 2025.03.31 |
[프로그래머스 C++] 3진법 뒤집기 (0) | 2025.03.31 |
[프로그래머스 C++] 내적 (0) | 2024.04.24 |
[프로그래머스 C++] 신규 아이디 추천 (0) | 2024.04.24 |