0

Palindrome Numbers

Sorry if my Engslish is too bad, but in this project I can pass test case 1,2,5,6; but I can't pass test case 3,4, someone can explain to help me where I'm wrong #include <iostream> #include <cmath> #include <vector> using namespace std; vector<int> assign_arr(int n, int max) { vector<int> arr; while ((n / max) != 0 && max != 1) { arr.push_back(n/max); n = n % max; max = max / 10; } arr.push_back(n); return arr; } bool isPalindrome(vector<int> arr) { //complete the function vector<int> arr_1 = arr; int x = arr_1.size(); cout << x << endl; if (arr_1.size() % 2 != 0) { for (int i = 0; i < arr_1.size(); i++) { if (arr_1[i] == arr_1[x] && i != x) { return true; } x = x - 1; } } else if (arr_1.size() % 2 == 0) { for (int i= 0; i < arr_1.size(); i++) { if(arr_1[i] == arr_1[x] && i < x) { return true; } x = x - 1; } } else if (arr_1.size() == 1) { return true; } return 0; } int main() { int n; cin >>n; cout << endl; int max = pow(10, 9); while (n/max == 0) //check the number of elements in the number { max = max / 10; } vector <int> arr = assign_arr(n,max); if(isPalindrome(arr)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }

7th Oct 2022, 7:04 AM
Minh Tân
Minh Tân - avatar
1 Answer
0
You should tell about those cases u cant satisfy
9th Oct 2022, 10:06 AM
Yash Raj
Yash Raj - avatar