-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlength_of_string.cpp
More file actions
73 lines (67 loc) · 1.22 KB
/
Copy pathlength_of_string.cpp
File metadata and controls
73 lines (67 loc) · 1.22 KB
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
#include<iostream>
using namespace std;
char lowertoupper(char ch) //for treating the uppercase as lowercase
{
if(ch>='a' && ch<='z') //for lc: 97 to 122
//fir uc: 65 to 90
{
//lowercase
return ch;
}
else
{
char temp=ch-'A'+'a';
return temp;
//uppercase to lowercase
}
}
bool ispalindrome(char string[],int n)
{
int s=0;
int e=n-1;
while (s<=e)
{
/* code */
// if(string[s]!=string[e]) //first and last not equal
if(lowertoupper(string[s])!=lowertoupper(string[e])) //string not case sensitive
{
return 0;
}
else
{
s++;
e--;
}
}
//matlab pura equal palindrome so return 1
return 1;
}
void reverse(char string[],int n)
{
int s=0;
int e=n-1;
while (s<e)
{
/* code */
swap(string[s++],string[e--]);
}
}
int length(char string[])
{
int len=0;
for(int i=0;string[i]!='\0';i++)
{
len++;
}
return len;
}
int main()
{
char name[20];
cin>>name;
int k=length(name);
// reverse(name,k);
// cout<<name;
cout<<ispalindrome(name,k);
return 0;
}