-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify_string_palindrome.cpp
125 lines (64 loc) · 1.29 KB
/
verify_string_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include<iostream>
#include<string>
using namespace std;
string reverse(string s)
{
double len = s.length();
string temp = s;
for(int i = 0; i < len; i++)
{
s[i] = temp[len - 1 - i];
}
return s;
}
bool isPalindrome(string s)
{
if(s == "") return 1;
string temp = ""; // empty string
for(int i = 0; i < s.length(); i++)
{
while(isalnum(s[i]))
{
temp +=tolower( s[i]); // remove spaces and characters
i++;
}
}
/*
for(int i = 0; i < temp.length(); i++)
{
temp[i] = tolower(temp[i]);
}
*/
string p = reverse(temp);
if(temp == p)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
string test = "As I pee, sir, I see Pisa!";
// string test;
// cin >> test;
string other = "the";
string temp;
for(int i = 0; i < test.length(); i++)
{
cout << " i top = " << i << endl;
while(isalnum(test[i]))
{
temp += tolower(test[i]); // remove spaces and characters
cout << "temp = " << temp << endl;
i++;
cout << "i in loop = " << i << endl;
}
cout << "i bottom = " << i << endl;
}
if(other == test) cout << "H" << endl;
cout << isPalindrome(test) << endl;
return 0;
}