Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- int main()
- {
- char s[101];
- cin.getline(s, 101);
- int start = 0, lmax = 1, lung, i1, i2, n = strlen(s);
- for( int i = 1; i < n; i++ ){
- i1 = i-1;
- i2 = i+1;
- while( i1 >= 0 && i2 < n && s[i1] == s[i2] ){
- if( lmax <= i2 - i1 + 1 ){
- lmax = i2 - i1 + 1;
- start = i1;
- }
- i2++;
- i1--;
- }
- i1 = i-1;
- i2 = i;
- while( i1 >= 0 && i2 < n && s[i1] == s[i2] ){
- if( lmax <= i2 - i1 + 1 ){
- lmax = i2 - i1 + 1;
- start = i1;
- }
- i2++;
- i1--;
- }
- } // stop - start + 1 = lmax
- for( int i = start; i <= lmax+start-1; i++ ){
- cout << s[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement