-
Notifications
You must be signed in to change notification settings - Fork 4
/
isPalindrom.cpp
42 lines (32 loc) · 993 Bytes
/
isPalindrom.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
A palindrome is a word that reads the same backward or forward.
Write a function that checks if a given word is a palindrome. Character case should be ignored.
For example:
isPalindrome("Deleveled") should return true as character case should be ignored,
resulting in "deleveled", which is a palindrome since it reads the same backward and forward.
*/
#include <string>
#include <iostream>
using namespace std;
bool isPalindrom(string word)
{
int len = (word.length() - 1);
for (int i = 0; i <= len / 2; i++)
if (word[len - i] != word[i] && word[len - i] != char(word[i] + 32) && char(word[len - i] + 32) != word[i])
return false;
return true;
}
int main()
{
string word = "DeLEelEd";
if (isPalindrom(word) == true)
cout << "This string is a palindrome." << endl;
else
cout << "THis is not a palindrom." << endl;
system("PAUSE");
return 0;
}
//
// Created by Muhamed Karajic on February 13, 2018.
// Copyright © 2018 Muhamed Karajic. All rights reserved.
//