Given a String S, Check Whether The Given String S is Palindrome or Not. If The Given String is Palindrome Then Print "Palindrome" (Without Quotes) else Print "Not Palindrome" (Without Quotes)
Example:
Input: s = "madam"
Output: Palindrome
Approach
C++
#include <bits/stdc++.h>using namespace std;void palindromeString(string s){int n = s.size();int flag = 0;for (int i = 0; i < n / 2; i++){if (s[i] != s[n - i - 1]){flag = 1;break;}}if (flag == 0)cout << "Palindrome\n";elsecout << "Not Palindrome\n";}int main(){string s = "madam";palindromeString(s);return 0;}
No comments:
Post a Comment