Here I could have used char string1[] and it would have worked #include <iostream> #include<cstring> using namespace std; int main(){ string string1; int i, length; int flag = 0; cout << "Enter a string: "; cin >> string1; length = string1.size(); for(i=0;i < length ;i++){ if(string1[i] != string1[length-i-1]){ flag = 1; break; } } if ..

#### Category : palindrome

class Solution { public: string longestPalindrome(string s) { int n=s.length(); int table[n][n]; memset(table,0,sizeof(table)); //length 1 int i,j,k; for(i=0;i<n;i++) table[i][i]=1; int maxlength=1; int start; //length 2 for(i=0;i<n-1;i++){ if(s[i]==s[i+1]){ table[i][i+1]=1; maxlength=2; start=i; } } //length>=3 for(k=3;k<=n;k++){//k->length for(i=0;i<n-k+1;i++){//i->starting index j=i-k+1;//j->ending index of substring if(s[i]==s[j] && table[i+1][j-1]==1){ table[i][j]=1; start=i; maxlength=k; } } } return s.substr(i,i+maxlength); } }; This code ..

The following is the code of an nth even length palindrome, but i wanted to know the code for nth odd length palindrome. Ps. don’t downvote if you don’t know the answer. #include <bits/stdc++.h> using namespace std; // Function to find nth even length Palindrome string evenlength(string n) { // string r to store resultant ..

Write a program that initialize array of size 10, and prints all palindrome number in array The code so far: #include<iostream> using namespace std; int main() { int myarray[10], t, remainder, i, reversenum = 0; cout << "Enter values:" << endl; for (i = 0; i < 10; i++) { cin >> myarray[i]; t = ..

The Question is: You are given a number ‘N’ in the form of a string ‘S’, which is a palindrome. You need to find the greatest number strictly less than ‘N’ which is also a palindrome. I tried to solve this question but is giving wrong answer for some test cases. can anyone help me ..

i made this program to make a function to check if integar array is palindrome or not.it is always giving output that it is not a palidrome on every input. can you plz help me out? code: #include<iostream> using namespace std; void palindrome(int[],int[],int); int main() { int size=5; int array1[size]; int array2[size]; palindrome(array1,array2,size); } void ..

In the code I checked for almost all different types of test cases by collecting them from different websites, they all showed correct answers. But when I am submitting it shows wrong answer. Can someone help me out with the test case which is failing? I am very tensed regarding this and I shall be ..

i have this exercise:" consider some natural number n, if it is not a Palindrom number, change the order of the digits in reverse order and add the resulting number with the original number. If the sum is not a palindrom number, repeat the same procedure on that sum until a palindrom number is obtained. ..

i have this exercise:" consider some natural number n, if it is not a Palindrom number, change the order of the digits in reverse order and add the resulting number with the original number. If the sum is not a palindrom number, repeat the same procedure on that sum until a palindrom number is obtained. ..

I coded a program to identify whether a natural number is palindrome or not, but surprisingly while the results are accurate as you see in the screenShot ,but the error is timeout: the monitored command dumped core Can any one explain this error ? #include <iostream> #include <cmath> using namespace std; bool isPalindrome (int x) ..

## Recent Comments