forked from cs50/compare50
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5.cpp
36 lines (32 loc) · 1.02 KB
/
5.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
// C++ program to illustrate the
// iterators in vector
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> nums;
nums.push_back(3);
nums.push_back(2);
nums.push_back(4);
//nums.push_back(15);
vector<int> obj;
int target = 6;
for(int i=0;i<nums.size();i++)
{
//cout<<nums[i]<<" ";
for(int j=0;j<nums.size();j++){
if (i != j){
cout<<j<<"adsasda"<<endl;
if (nums[i] + nums[j] == target){
cout<<j<<"adsasda"<<endl;
obj.push_back(i);
obj.push_back(j);
cout<<"["<<i<<","<<j<<"]"<<endl;
//Because nums[0] + nums[1] == 9, we return [0, 1].
cout<<"Because nums["<<i<<"] "<<"+ nums["<<j<<"] "<<"== "<<target<<", we return ["<<i<<", "<<j<<"]."<<endl;
return 0;
}
}
}
}
}