Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define SIZE 100
- int main(){
- char str[SIZE];
- cin.getline(str, SIZE);
- int i = 0;
- int wstart = 0;
- int wend = 0;
- bool sym = false;
- int max_len = 0;
- int sym_w = -1;
- do{
- if( str[i] == ' ' || str[i] == '\0' ){
- wend = i;
- sym = true;
- for( int j = 0; j < ( (wend - wstart ) / 2); j++ )
- if( str[ wstart + j] != str[ wend - 1 - j ] )
- sym = false;
- if( sym && ( wend - wstart ) > max_len ){
- max_len = wend - wstart;
- sym_w = wstart;
- }
- wstart = wend + 1;
- }
- }while( str[i++] );
- if( sym_w == -1 ){
- cout << "Симметричных слов нет" << endl;
- }else{
- cout << "Самое длинное симместричное слово ";
- while( str[sym_w] != ' ' && str[sym_w] != '\0' )
- cout << str[sym_w++];
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement