Advertisement
STANAANDREY

Tpb32 3/2/2020

Feb 3rd, 2020
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. #define tokens " "
  6. #define NMAX 1000
  7. char v[NMAX][NMAX], s[NMAX], revs[NMAX];
  8. int n;
  9.  
  10. void rev(char s[])
  11. {
  12.     int n = strlen(s);
  13.     for (int i = 0; i < n / 2; i++)
  14.         swap(s[i], s[n - i - 1]);
  15. }
  16.  
  17. int main()
  18. {
  19.     cin.getline(s, NMAX);
  20.     char *p = strtok(s, tokens);
  21.     while (p)
  22.     {
  23.         strcpy(v[n], p);
  24.         n++;
  25.         p = strtok(NULL, tokens);
  26.     }
  27.  
  28.     for (int i = 0; i < n - 1; i++)
  29.         for (int j = i + 1; j < n; j++)
  30.         {
  31.             strcpy(revs, v[j]);
  32.             rev(revs);
  33.             if (!strcmp(revs, v[i]))
  34.                 cout << v[i] << ' ' << v[j] << endl;
  35.         }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement