RuslanMag

Переворот слов

Nov 12th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 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.     char t[N];
  10.     cin.getline(s, N);
  11.  
  12.     int len = strlen(s);
  13.     int lenth = 0;
  14.  
  15.     for (int j = len - 1; j > 0; j--)
  16.     {
  17.         while (s[j] == ' ' && j != 0)
  18.         {
  19.             j--;
  20.         }
  21.         int end = j;
  22.         while (s[j] != ' ' && j != 0)
  23.         {
  24.             j--;
  25.         }
  26.         int beg;
  27.         if (j != 0)
  28.         {
  29.             beg = j + 1;
  30.         }
  31.         else
  32.         {
  33.             beg = j;
  34.         }
  35.        
  36.         for (int i = beg, x = 0 + lenth; i <= end; i++, x++)
  37.         {
  38.             t[x] = s[i];
  39.         }  
  40.  
  41.         lenth += end - beg + 2;
  42.  
  43.         t[lenth - 1] = ' ';
  44.        
  45.         //cout << beg << ' ' << end << ' ' << lenth << endl;
  46.     }
  47.  
  48.     t[lenth - 1] = '\0';
  49.  
  50.     cout << t;
  51. }
Add Comment
Please, Sign In to add comment