fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <unordered_map>
  4. #include <cstdlib>
  5.  
  6. int main()
  7. {
  8. // read in the values instead of this
  9. const int value_of_credit = 200 ;
  10. const int available[] = { 1, 2, 67, 3, 4, 133, 5, 6, 7, 8, 9 } ;
  11. const std::size_t N = sizeof(available)/sizeof(*available) ;
  12.  
  13. std::unordered_map<int,int> map ;
  14. for( std::size_t pos = 0 ; pos < N ; ++pos )
  15. {
  16. auto iter = map.find( available[pos] ) ;
  17. if( iter != map.end() )
  18. {
  19. std::cout << iter->second << ' ' << pos << '\n' ;
  20. return EXIT_SUCCESS ;
  21. }
  22. else map[ value_of_credit - available[pos] ] = pos ;
  23. }
  24. // return EXIT_FAILURE ; // no solutio
  25. }
  26.  
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
2 5