fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4. #include <numeric>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. int inputs[899];
  10. int max[2] = { 0, 0 };
  11. auto max_product = 0;
  12.  
  13. iota(begin(inputs), end(inputs), 100);
  14.  
  15. for(auto it = crbegin(inputs); it != crend(inputs) && *it * *it > max_product; ++it) {
  16. const auto rhs = find_if(it, crend(inputs), [lhs = *it](const auto rhs){
  17. const auto input = to_string(lhs * rhs);
  18.  
  19. return equal(cbegin(input), next(cbegin(input), input.size() / 2U), crbegin(input));
  20. });
  21.  
  22. if(crend(inputs) != rhs){
  23. const auto product = *it * *rhs;
  24.  
  25. if(product > max_product) {
  26. max_product = product;
  27. max[0] = *it;
  28. max[1] = *rhs;
  29. }
  30. }
  31. }
  32. cout << max[0] << " * " << max[1] << " = " << max_product << endl;
  33. }
Success #stdin #stdout 0.01s 4440KB
stdin
Standard input is empty
stdout
993 * 913 = 906609