Advertisement
Guest User

Untitled

a guest
May 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. int main()
  5. {
  6.     char s[101], x[10][101];
  7.     int counter = 0;
  8.     cin.getline(s, 101);
  9.     char *p = strtok(s, " ");
  10.     while(p != NULL)
  11.     {
  12.         bool ok = true;
  13.         for(int i = 0, j = strlen(p)-1; i< j && ok == 1; i++, j--)
  14.         {
  15.             if(p[i] != p[j])
  16.                 ok = false;
  17.         }
  18.         if(ok == true)
  19.             strcpy(x[++counter], p);
  20.         p = strtok(NULL, " ");
  21.     }
  22.     for(int i = 1; i<counter; i++)
  23.         for(int j = i + 1; j<=counter; j++)
  24.             if(strcmp(x[i], x[j]) < 0)
  25.             {
  26.                 char c[101];
  27.                 strcpy(c, x[i]);
  28.                 strcpy(x[i], x[j]);
  29.                 strcpy(x[j], c);
  30.             }
  31.     for(int i = 1; i<=counter; i++)
  32.         cout << x[i] <<' ';
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement