fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. bool isPalindrome(int num)
  6. {
  7. if (num < 10)
  8. return true;
  9.  
  10. int leftDigit;
  11. int rightDigit;
  12. int numDigits;
  13.  
  14. while (num > 9)
  15. {
  16. rightDigit = num % 10;
  17. numDigits = (int)log10(num);
  18. leftDigit = (int)(num / pow(10, numDigits));
  19.  
  20. cout << "Left: " << leftDigit << " Right: " << rightDigit << endl;
  21.  
  22. if (leftDigit != rightDigit)
  23. return false;
  24.  
  25. if (num % 100 == 0)
  26. {
  27. if ((int)(num / pow(10, numDigits - 1)) % 10 != 0)
  28. return false;
  29. else
  30. {
  31. num -= (int)pow(10, numDigits - 1);
  32. num /= 100;
  33. continue;
  34. }
  35. }
  36.  
  37. num -= (int)pow(10, numDigits);
  38. num /= 10;
  39. }
  40. return true;
  41. }
  42.  
  43. int main() {
  44.  
  45. int a = 999, b, maxProd = 0;
  46. cout << isPalindrome(906609) << endl;
  47. /*while (a > 99)
  48. {
  49. b = a;
  50. while (b > 99)
  51. {
  52. int product = a * b;
  53. if (a == 993 && b == 913)
  54. cout << a << " " << b << " " << product << endl;
  55. if (isPalindrome(product))
  56. {
  57.  
  58. if (product > maxProd)
  59. maxProd = product;
  60. }
  61. b--;
  62. }
  63. a--;
  64. }
  65.  
  66. cout << maxProd << endl;*/
  67.  
  68. return 0;
  69. }
Success #stdin #stdout 0s 4484KB
stdin
Standard input is empty
stdout
Left: 9 Right: 9
Left: 8 Right: 0
0