Ankit_132

B

Sep 16th, 2023
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string s;
  8.     cin>>s;
  9.  
  10.     int ans = 1;
  11.  
  12.     int n = s.size();
  13.  
  14.     auto isPal = [&](int l, int r)
  15.     {
  16.         for(int i=l, j=r; i<j; i++, j--)
  17.         {
  18.             if(s[i] != s[j])
  19.                 return false;
  20.         }
  21.  
  22.         return true;
  23.     };
  24.  
  25.     for(int i=0; i<n; i++)
  26.     {
  27.         for(int j=i+1; j<n; j++)
  28.         {
  29.             if(isPal(i, j))
  30.                 ans = max(ans, j-i+1);
  31.         }
  32.     }
  33.  
  34.     cout<<ans<<"\n";
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment