kolioi

24. Reverse String C++

Dec 2nd, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. void ReverseString(std::string&);
  5.  
  6. int main()
  7. {
  8.     std::string s;
  9.     std::cin >> s;
  10.  
  11.     ReverseString(s);
  12.  
  13.     std::cout << s << std::endl;
  14.  
  15.     return 0;
  16. }
  17.  
  18. void ReverseString(std::string& s)
  19. {
  20.     for (int i = 0; i < s.length() / 2; ++i)
  21.     {
  22.         char ch = s[i];
  23.         s[i] = s[s.length() - i - 1];
  24.         s[s.length() - i - 1] = ch;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment