PALINDROME

PROBLEM LINK:

Practice

Author: RushikeshThakare
Tester: ram agrawal
Editorialist: NiprasadBirajdar

DIFFICULTY:

CAKEWALK, EASY.

PREREQUISITES:

None

PROBLEM:

Determine whether an integer is a palindrome. An integer is a palindrome if reverse of a number is equal to the number itself.

  • For Example:-121
  • Reverse of number 121 = 121 ,Hence this is the palindrome number
Setter's Solution

#include
using namespace std;

int main()
{

string s;
int k,t;
cin>>t;
for(k=0;k<t;k++){
cin >> s;
int l = 0;
int h = s.length()-1;

while(h > l){
    if(s[l++] != s[h--]){
        cout << "Number is not Palindrome" << endl;
        return 0;
    }
}
cout << "Number is Palindrome" << endl;
}
return 0;

}

Tester's Solution

#include
using namespace std;

int main()
{
int t, n, num, digit, rev = 0;

 cin>>t;
 for(int i=1;i<=t;i++)
 {
 cin >> num;

 n = num;

 do
 {
     digit = num % 10;
     rev = (rev * 10) + digit;
     num = num / 10;
 } while (num != 0);

 if (n == rev)
     cout << "Number is Palindrome"<<endl;
 else
     cout << "Number is not palindrome"<<endl;
}
return 0;

}

Editorialist's Solution

#include
using namespace std;

int main()
{
// your code goes here
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int temp, sum=0;
int rem;
temp=n;
while(n>0)
{
rem=n%10;
sum=(sum*10)+rem;
n=n/10;
}
if(sum==temp)
{
cout<<“Number is Palindrome”<<"\n";
}
else
{
cout<<“Number is not Palindrome”<<"\n";
}
}
return 0;
}