Guest User

Untitled

a guest
May 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. /* I have a O(len/2) method. I never worked in Delphi, so I'll post the code in C++ (2010 << I hope there's no problem >> ): */
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main(void)
  6. {
  7.     char S[128], temp;
  8.     cout << "Original string = "; cin.getline(S, sizeof(S));
  9.     for(int i(0), j = strlen(S), k(j >> 1), x; i < k; ++i)
  10.     {
  11.         // Swap
  12.         x = j - i - 1;
  13.         S[i] ^= S[x];
  14.         S[x] ^= S[i];
  15.         S[i] ^= S[x];
  16.     }
  17.     cout << "Reverse string = " << S;
  18.     system("pause>nul");
  19.     return EXIT_SUCCESS;
  20. }
Add Comment
Please, Sign In to add comment