fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int arr[]= {1, -2, 1, 0, 5};
  6. int n=sizeof(arr)/sizeof(arr[0]);
  7. int x=0;
  8. bool flag=false;
  9. unordered_set<int> mp;
  10. for(int j=0;j<n;j++)
  11. {
  12. int diff=x-arr[j];
  13. if(mp.find(diff)!=mp.end()){
  14. flag=true;
  15. cout<<"true";
  16. break;
  17. }
  18. mp.insert(arr[j]);
  19. }
  20. if(flag==false)
  21. cout<<"false";
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
false