Advertisement
a53

ReverseWords

a53
Dec 10th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. void ReverseWords(char s[])
  2. {
  3. int i=0,k=0;
  4. while(s[i]!='\0')
  5. {
  6. if(s[i]!=' ')
  7. ++k;
  8. else
  9. {
  10. int p=1;
  11. if(k%2)
  12. for(int j=i-k;j<=i-k+k/2;++j)
  13. swap(s[j],s[i-p]),++p;
  14. else
  15. for(int j=i-k;j<i-k+k/2;++j)
  16. swap(s[j],s[i-p]),++p;
  17. k=0;
  18. }
  19. ++i;
  20. }
  21. int p=1;
  22. if(k%2)
  23. for(int j=i-k;j<=i-k+k/2;++j)
  24. swap(s[j],s[i-p]),++p;
  25. else
  26. for(int j=i-k;j<i-k+k/2;++j)
  27. swap(s[j],s[i-p]),++p;
  28. for(int j=0;j<i/2;++j)
  29. swap(s[j],s[i-j-1]);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement