-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtwo_sum.cpp
42 lines (40 loc) · 817 Bytes
/
two_sum.cpp
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
36
37
38
39
40
41
42
#include <bits/stdc++.h>
using namespace std;
vector<int> twoSum(vector<int> &nums, int x)
{
vector<int> ans;
for (int i = 0; i < nums.size(); i++)
{
for (int j = 0; j < nums.size(); j++)
{
if (nums[i] + nums[j] == x && i != j)
{
ans.push_back(i);
ans.push_back(j);
return ans;
}
}
}
return ans;
}
int main()
{
int t;
cin >> t;
while (t--)
{
int n, k;
cin >> n >> k;
vector<int> nums;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
nums.push_back(temp);
}
vector<int> v = twoSum(nums, k);
for (auto i : v)
cout << i << " ";
cout << endl;
}
}