fueanta

Palindrome or not? [String Version]

Jun 1st, 2017
128
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Runtime: 142 ms
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Solution {
  8. public:
  9.     bool isPalindrome(int x) {
  10.         string number = to_string(x);
  11.         int size = number.size();
  12.         bool checker = true;
  13.  
  14.         for (int j = 0; (j < size / 2) && checker; j++) {
  15.             if (number[j] != number[(size - 1) - j])
  16.                 checker = false;
  17.         }
  18.         return checker;
  19.     }
  20. };
  21.  
  22. int main(void)
  23. {
  24.     Solution s;
  25.     int num = 112; // 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