Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int m,a,i,sum,r,c=0;;
- cin>>m;
- if(m<=0||m>=100)
- {
- cout<<"Invalid input"<<endl;
- return 0;
- }
- unordered_map<int,int>mp;
- for(i=0; i<m; i++)
- {
- cin>>a;
- mp[a]++;
- }
- cin>>sum;
- for(auto j:mp)
- {
- if(j.second>0)
- {
- r=sum-j.first;
- if(mp.find(r)!=mp.end())
- {
- if(c==0)
- cout<<"Pairs with sum "<<sum<<" are:";
- cout<<" ("<<j.first<<","<<r<<") ";
- c=1;
- mp[r]=0;
- j.second=0;
- }
- }
- }
- if(c==0)
- cout<<"No pairs found"<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment