fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <unordered_map>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. int main(){
  11.  
  12. unordered_map<int,int> numbers;
  13. bool flag = false;
  14.  
  15. while(cin){
  16. auto buffer = 1;
  17. cin >> buffer;
  18. numbers.insert({buffer,buffer});
  19. }
  20.  
  21. for(auto it : numbers){
  22. int zeroSum = 0 - it.second;
  23. auto t = numbers.find(zeroSum);
  24. if(t != numbers.end()){
  25. cout << it.first << " and " << t->second << " add up to zero " << endl;
  26. flag = true;
  27. }
  28. }
  29.  
  30. cout << "Function returned " << flag << endl;
  31. }
Success #stdin #stdout 0s 16064KB
stdin
	1
		2
		3
		-5
		-3
		-1
		2
		4
		6
stdout
-1 and 1 add up to zero 
1 and -1 add up to zero 
-3 and 3 add up to zero 
3 and -3 add up to zero 
Function returned 1