RuslanMag

Слово буквами наоборот

Nov 12th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     const int N = 10000;
  8.     char s[N];
  9.     cin.getline(s, N);
  10.  
  11.     for (int i = 0; s[i]; )
  12.     {
  13.         while (s[i] == ' ')
  14.         {
  15.             i++;
  16.         }
  17.         if (s[i] == 0)
  18.         {
  19.             break;
  20.         }
  21.         int beg = i;
  22.         while (s[i] && s[i] != ' ')
  23.         {
  24.             i++;
  25.         }
  26.         int end = i - 1;
  27.         //cout << beg << ' ' << end << endl;
  28.         for (int i = beg, j = end; i < j; i++, j--)
  29.         {
  30.             swap(s[i], s[j]);
  31.         }
  32.         for (int i = beg; i <= end; i++)
  33.         {
  34.             cout << s[i];
  35.         }
  36.         cout << ' ';
  37.     }
  38.  
  39. }
Add Comment
Please, Sign In to add comment