forked from bishweashwarsukla/hactoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalid_palindrome
38 lines (32 loc) · 942 Bytes
/
valid_palindrome
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
class Solution {
public:
bool isPalindrome(string s) {
int j=s.length()-1;
int i=0;
for (int k=0;k<s.length();k++){
bool test=true;
bool test1=true;
if ((s[i]>=48 && s[i]<=57)||(s[j]>=48 && s[j]<=57))test=false;
if (s[j]>=48 && s[j]<=57)test1=false;
if(test &&('A'>s[i] ||('Z'<s[i]&& 'a'>s[i])|| 'z'<s[i] )){i++;continue;}
if(test1 &&( 'A'>s[j] ||('Z'<s[j]&&'a'>s[j])|| 'z'<s[j])){j--;continue;}
cout<<int(s[i])<<int(s[j]);
if (65<=(int (s[i])) && (int (s[i]))<=90){
s[i]=s[i]-'A'+'a';
}
if (65<=int (s[j]) && (int (s[j]))<=90){
s[j]=s[j]-'A'+'a';
}
if (s[i]!=s[j])return false;
i++;
j--;
}
return true;
}
};
int main()
{
Solution obj;
bool ans=obj.isPalindrome("noon");
cout<<ans;
}