-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path125.cpp
37 lines (29 loc) · 820 Bytes
/
125.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
//Valid Palindrome
//can make it without creating the new_string string , by mutating only the original string s
#include <iostream>
#include <string>
using namespace std;
bool isPalindrome(string s) {
string new_string="";
for (int i=0;i<s.length();i++){
if (isupper(s[i])){
new_string+=tolower(s[i]);
}
else if ((s[i]>=97 && s[i]<=122) || (s[i]>=48 && s[i]<=57)){
new_string+=s[i];
}
}
cout<<new_string<<endl;
for (int i=0;i<new_string.length()/2;i++){
if (new_string[i]!=new_string[new_string.length()-i-1]){
return false;
}
}
return true;
}
int main(){
//string s = "A man, a plan, a canal: Panama";
string s="0P";
bool result=isPalindrome(s);
cout<<result;
}