fork download
  1. #include <iostream>
  2. #include<vector>
  3. #include<unordered_map>
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8. vector<int> a={1,3,4,5,2,7,8};
  9. unordered_map<int,int> m;
  10. int k=-7;
  11. for(int i=0;i<a.size();i++) {
  12. int sec=a[i]+k;
  13. if(m.find(sec)!=m.end()) {
  14. cout<<a[i]<<" "<<sec<<endl;
  15. }
  16. m[a[i]]=i;
  17. }
  18. return 0;
  19. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
8 1