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], x[10][101];
- int counter = 0;
- cin.getline(s, 101);
- char *p = strtok(s, " ");
- while(p != NULL)
- {
- bool ok = true;
- for(int i = 0, j = strlen(p)-1; i< j && ok == 1; i++, j--)
- {
- if(p[i] != p[j])
- ok = false;
- }
- if(ok == true)
- strcpy(x[++counter], p);
- p = strtok(NULL, " ");
- }
- for(int i = 1; i<counter; i++)
- for(int j = i + 1; j<=counter; j++)
- if(strcmp(x[i], x[j]) < 0)
- {
- char c[101];
- strcpy(c, x[i]);
- strcpy(x[i], x[j]);
- strcpy(x[j], c);
- }
- for(int i = 1; i<=counter; i++)
- cout << x[i] <<' ';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement