Wed Nov 06 2019
Palindrome String
C++ Programming1602 views
File Name: palindrome-string.cpp
#include<iostream>
/* Contains functions for manipulating data */
#include<algorithm>
using namespace std;
int main() {
/* Declear string type variable in C++ */
string str;
cout << "Check the given string is Palindrome or not" << endl;
cout << "Enter a string:" << endl;
cin >> str;
/* begin() and end() rbegin() are iterators for beginning and end */
/* equal() compares the elements */
if(equal(str.begin(), str.end(), str.rbegin()))
cout << "It's a palindrome string" << endl;
else
cout << "It's not a palindrome string!" << endl;
return 0;
}
/* Output */
Check the given string is Palindrome or not
Enter a string:
abcba
It's a palindrome string!
/* ---------------------------------- */
Check the given string is Palindrome or not
Enter a string:
asdfg
It's not a palindrome string!
Reference:
Palindrome string
Author:Geekboots