Palindrome String

PROBLEM :

Given a string s check if it is palindrome or not.

Input:
The first line contains 'T' denoting the number of testcases. Then follows description of testcases.
Each case begins with a single integer N denoting the length of string. The next line contains the string s.


Output:
Print "Yes" if it is a palindrome else "No". (Without the double quotes)


Constraints:
1<=T<=30
1<=N<=100


Example:
Input:
1
4
abba

Output:
Yes

--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std;
int main()
 {
int t,n,i,j ;
char str[100] ;
cin>>t ;
while(t--)
{
   cin>>n ;
 
   for(i=0;i<n;i++)
       cin>>str[i] ;
 
   i=0;
   j=n-1 ;
 
   while(i<j&&i!=j)
   {
       if(str[i]!=str[j])
           break ;
       i++ ;
       j-- ;
   }
 
   if(i==j||i>j)
       cout<<"Yes" ;
   else
       cout<<"No" ;
     
   cout<<endl ;
 
}
return 0;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )