-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallengedia11.cpp
41 lines (39 loc) · 920 Bytes
/
challengedia11.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
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;
/*esta funcion es para limpiar la cadena*/
string cleanString(const string& str) {
string cleaned;
for (char c : str) {
if (isalnum(c)) {
cleaned += tolower(c);
}
}
return cleaned;
}
bool isPalindrome(const string& str) {
string cleaned = cleanString(str);
int left = 0;
int right = cleaned.size() - 1;
while (left < right) {
if (cleaned[left] != cleaned[right]) {
return false;
}
left++;
right--;
}
return true;
}
int main() {
string input;
cout << "Ingrese una cadena de caracteres: ";
getline(cin, input);
if (isPalindrome(input)) {
cout << "La cadena es un palindromo." << endl;
} else {
cout << "La cadena no es un palindromo." << endl;
}
return 0;
}