-
Notifications
You must be signed in to change notification settings - Fork 0
/
day5.cpp
65 lines (57 loc) · 1.24 KB
/
day5.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
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
bool isPalindrome(string s)
{
int length=s.length();
int flag=0;
for (int i = 0; i < length; i++)
{
if (s[i] != s[length - i - 1])
{
flag = 1;
break;
}
}
if (flag == 1)
return false;
else
return true;
}
int lengthofpal(string s)
{
return s.length();
}
int minChar(string str)
{
int sub = 0;
int len = str.length();
string s1 = str;
// Write your code here
for (int i = 0; i < str.length(); i++)
{
s1 = s1.substr(0, len);
// cout<<"substring at this point is:"<<s1<<"\n";
// cout<<"ispallindrome bool value is "<<isPalindrome(s1)<<"\n";
if (isPalindrome(s1)==0)
{
len = len - 1;
continue;
}
else
{
sub = lengthofpal(s1);
break;
}
}
// return str.length() - sub;
return sub;
}
int main()
{
string str;
cout << "enter string\n";
cin >> str;
cout << minChar(str);
}