Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <list>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. string reverse(string str)
  11. {
  12. string revStr = "";
  13. for (int i = str.length() - 1; i >= 0; i--)
  14. {
  15. revStr += str[i];
  16. }
  17. return revStr;
  18. }
  19.  
  20. int main()
  21. {
  22. string str;
  23. getline(cin, str);
  24.  
  25. string word;
  26. string result;
  27.  
  28. for (int i = str.length() - 1; i >= 0; i--)
  29. {
  30. if (str[i] == ' ')
  31. {
  32. if (word.length() == 0)
  33. {
  34. continue;
  35. }
  36. result += reverse(word) + " ";
  37. word = "";
  38. }
  39. else
  40. {
  41. word += str[i];
  42. }
  43. }
  44. cout << result + reverse(word) << endl;
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement