Advertisement
qberik

Untitled

Nov 18th, 2021
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #define SIZE 100
  6.  
  7. int main(){
  8.  
  9.   char str[SIZE];
  10.  
  11.   cin.getline(str, SIZE);
  12.  
  13.   int i = 0;
  14.   int wstart = 0;
  15.   int wend = 0;
  16.   bool sym = false;
  17.   int max_len = 0;
  18.   int sym_w = -1;
  19.   do{
  20.     if( str[i] == ' ' || str[i] == '\0' ){
  21.       wend = i;
  22.       sym = true;
  23.       for( int j = 0; j < ( (wend - wstart ) / 2); j++ )
  24.         if( str[ wstart + j] != str[ wend - 1 - j ] )
  25.           sym = false;
  26.       if( sym && ( wend - wstart ) > max_len ){
  27.         max_len = wend - wstart;
  28.         sym_w = wstart;
  29.       }
  30.       wstart = wend + 1;
  31.     }
  32.   }while( str[i++] );
  33.  
  34.   if( sym_w == -1 ){
  35.     cout << "Симметричных слов нет" << endl;
  36.   }else{
  37.     cout << "Самое длинное симместричное слово ";
  38.     while( str[sym_w] != ' ' && str[sym_w] != '\0' )
  39.       cout << str[sym_w++];
  40.     cout <<  endl;
  41.  
  42.   }
  43.  
  44.   return 0;
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement