pallindrome string

Solutions on MaxInterview for pallindrome string by the best coders in the world

showing results for - "pallindrome string"
Noemi
03 Mar 2018
1#include <iostream>
2using namespace std;
3
4bool isPalindrome(string str)
5{
6    int j = str.length() - 1;
7
8    for (int i = 0; i < j; i++, j--)
9    {
10        if (str[i] != str[j])
11        {
12            return false;
13        }
14    }
15
16    return true;
17}
18
19int main()
20{
21    string words[5] = {"mom", "radar", "level", "hello", "one"};
22    for (int i = 0; i < 5; i++)
23    {
24        if (isPalindrome(words[i]))
25        {
26            cout << words[i] << " -> Palindrome" << endl;
27        }
28        else
29        {
30            cout << words[i] << " -> Not a Palindrome" << endl;
31        }
32    }
33
34    return 0;
35}