Advertisement
Glenpl

Untitled

Jun 24th, 2015
296
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 <string>
  3. #include <algorithm>
  4.  
  5. void swap( std::string &str, int index1, int index2 )
  6. {
  7.     char x = str[index1];
  8.     str[index1] = str[index2];
  9.     str[index2] = x;
  10. }
  11.  
  12. std::string zmienione_metoda_z_polecenia( std::string str )
  13. {
  14.     for(auto i = 0; i < str.length() / 2; i++)
  15.         swap( str, i, ( str.length() - 1 - i ) );
  16.     return str;
  17. }
  18.  
  19. std::string reverse( std::string str )
  20. {
  21.     std::reverse( str.begin(), str.end() );
  22.     return str;
  23. }
  24.  
  25. int main()
  26. {
  27.     std::string str = "programowanie";
  28.  
  29.     std::cout << reverse( str ) << "\n";
  30.  
  31.     std::cout << zmienione_metoda_z_polecenia( str ) << "\n";
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement