-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalindrome.cpp
37 lines (35 loc) · 871 Bytes
/
palindrome.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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
class Solution {
public:
static bool isNotAlpha(char c){
return !(std::isalpha(c)||std::isdigit(c));
}
static bool compareChar(char & c1, char & c2)
{
if (c1 == c2)
return true;
else if (std::toupper(c1) == std::toupper(c2))
return true;
return false;
}
bool isPalindrome(std::string s) {
//std::remove_if(s.begin(), s.end(), isNotAlpha);
s.erase(remove_if(s.begin(), s.end(), isNotAlpha ), s.end());
std::string rs(s.begin(), s.end());
std::cout<<s<<"\n";
std::reverse(rs.begin(), rs.end());
std::cout<<rs<<"\n";
return std::equal(s.begin(), s.end(), rs.begin(), compareChar);
}
};
int main(){
//std::string st("race a car");
// std::string st("ada");
std::string st("0F");
Solution s;
std::cout<<s.isPalindrome(st);
return 1;
}