-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.txt
More file actions
65 lines (62 loc) · 2.06 KB
/
Copy pathPalindrome.txt
File metadata and controls
65 lines (62 loc) · 2.06 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
-----------------------------------------------------------------------------
Question 1. Create a function to determine if a word or phrase is a palindrome.
The function will take as input a string and return a boolean that is true if the
word or phrase is a palindrome and false otherwise.
-----------------------------------------------------------------------------
#include <iostream>
#include <string>
using namespace std;
bool IsPalindromic(string& strInput);
int main()
{
string str;
cout << "Enter a string to check for palindromic: ";
getline(cin, str);
cout << "\"" << str << "\"" << " is " << (IsPalindromic(str) ? "" : "NOT") << " palindromic";
}
/**
* @description: A function to check whether the given string is palindromic or not
* @params: strInput - input string
* @return: bool - true if palindromic, false otherwise
*/
bool IsPalindromic(string& strInput)
{
size_t size = strInput.length();
for (int i = 0; i <= size / 2; i++)
{
if (toupper(strInput.at(i)) != toupper(strInput.at(strInput.length() - 1 - i)))
{
return false;
}
}
return true;
}
*********************************************************************************************
Testcase-1
-----------------
Enter a string to check for palindromic: 19591
"19591" is palindromic
Testcase-2
-----------------
Enter a string to check for palindromic: 2002
"2002" is palindromic
Testcase-3
-----------------
Enter a string to check for palindromic: 1587
"1587" is NOT palindromic
Testcase-4
-----------------
Enter a string to check for palindromic: madam madam madam
"madam madam madam" is palindromic
Testcase-5
-----------------
Enter a string to check for palindromic: Step on no pets
"Step on no pets" is palindromic
Testcase-6
-----------------
Enter a string to check for palindromic: Dad
"Dad" is palindromic
Testcase-7
-----------------
Enter a string to check for palindromic: A quick clever brown fox jumps over the lazy Dog
"A quick clever brown fox jumps over the lazy Dog" is NOT palindromic