forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAC_simulation_n.cpp
More file actions
38 lines (33 loc) · 834 Bytes
/
Copy pathAC_simulation_n.cpp
File metadata and controls
38 lines (33 loc) · 834 Bytes
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
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_simulation_n.cpp
* Create Date: 2014-12-21 08:19:49
* Descripton: simulation
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
public:
bool isPalindrome(string s) {
int left = 0, right = s.length() - 1;
while (left < right) {
if (!isalpha(s[left]) && !isdigit(s[left]))
left++;
else if (!isalpha(s[right]) && !isdigit(s[right]))
right--;
else if (tolower(s[left]) != tolower(s[right]))
return false;
else
left++, right--;
}
return true;
}
};
int main() {
string a;
Solution s;
while (getline(cin, a))
cout << s.isPalindrome(a) << endl;
return 0;
}