-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy path03.cpp
More file actions
35 lines (25 loc) · 902 Bytes
/
Copy path03.cpp
File metadata and controls
35 lines (25 loc) · 902 Bytes
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
32
33
34
35
#include <vector>
#include <set>
using namespace std;
vector<int> solution(vector<int> numbers) {
set<int> sum; // ❶ 두 수의 합을 저장할 저장공간 선언
for(int i = 0;i<numbers.size();++i) // ❷ 반복문을 수행하면서 두 수의 합을 저장
for(int j = i+1 ; j< numbers.size();++j)
sum.insert(numbers[i] + numbers[j]);
vector<int> answer(sum.begin(), sum.end()); // ❸ 반환타입을 맞추기 위헤 벡터로 변환
return answer;
}
//아래 코드는 테스트 코드 입니다.
#include <iterator>
#include <iostream>
void print(vector<int> vec)
{
copy(vec.begin(), vec.end(), std::ostream_iterator<int>(cout, " "));
cout << endl;
}
int main()
{
print(solution({2, 1, 3, 4, 1})); // 2 3 4 5 6 7
print(solution({5, 0, 2, 7})); // 2 5 7 9 12
return 0;
}