fueanta

Palindrome or not? [Reverse Version]

Jun 1st, 2017
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Runtime: 142 ms
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class Solution {
  7. public:
  8.     bool isPalindrome(int x) {
  9.         if (x < 0)
  10.             return false;
  11.         int mainCopy = x, rev = 0;
  12.         while (x != 0)
  13.         {
  14.             rev *= 10;
  15.             rev += (x % 10);
  16.             x /= 10;
  17.         }
  18.         return (mainCopy == rev);
  19.     }
  20. };
  21.  
  22. int main(void)
  23. {
  24.     Solution s;
  25.     int num = 2112; // change the number from here
  26.     if (s.isPalindrome(num))
  27.     {
  28.         cout << "\nPalindrome..!\n\n";
  29.     }
  30.     else
  31.     {
  32.         cout << "\nNot Palindrome..!\n\n";
  33.     }
  34.     return 0;
  35. }
RAW Paste Data