-
Notifications
You must be signed in to change notification settings - Fork 0
/
pc.cpp
43 lines (34 loc) · 880 Bytes
/
pc.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
43
#include <iostream>
#include <string>
#include <cctype> // For std::tolower
using namespace std;
bool isPalindrome(const string &word) {
string cleanWord;
// Remove spaces and convert to lowercase for case-insensitive comparison
for (char ch : word) {
if (!isspace(ch)) {
cleanWord += tolower(ch);
}
}
int start = 0;
int end = cleanWord.length() - 1;
while (start < end) {
if (cleanWord[start] != cleanWord[end]) {
return false;
}
start++;
end--;
}
return true;
}
int main() {
string userWord;
cout << "Enter a word: ";
cin >> userWord;
if (isPalindrome(userWord)) {
cout << "YES, IT IS PALINDROME" << endl;
} else {
cout << "NO, IT IS NOT A PALINDROME" << endl;
}
return 0;
}