-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.cpp
54 lines (51 loc) · 1.04 KB
/
1.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
43
44
45
46
47
48
49
50
51
52
53
54
/*
5
-1 -2 -3 -4 -5
-8
*/
#include <iostream>
#include <algorithm>
#include<vector>
#include<map>
using namespace std;
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target)
{
vector<int>ans;
map<int,int>M;
for(int i=0;i<nums.size();i++) M[nums[i]]=i+1;
for(map<int,int>::iterator it=M.begin();it!=M.end();it++)
{
cout<<it->first<<" "<<it->second<<endl;
}
cout<<"------------------"<<endl;
for(int i=0;i<nums.size();i++)
{
int MMM=M[target-nums[i]];
if(MMM!=i+1&&MMM>0)
{
ans.push_back(i);
ans.push_back(MMM-1);
break;
}
}
return ans;
}
}x;
int main()
{
vector<int>input;
int n;int tmp;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>tmp;
input.push_back(tmp);
}
cin>>tmp;
vector<int>ans=x.twoSum(input,tmp);
for(int i=0;i<ans.size();i++) cout<<ans[i]<<" ";
cout<<endl;
return 0;
}