Last active
December 19, 2015 16:19
-
-
Save ygabo/5983321 to your computer and use it in GitHub Desktop.
Reverse string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
void rev(string &x){ | |
int j = x.length()-1; | |
for( int i = 0; i < x.length()/2; ++i){ | |
swap(x[i], x[j--]); | |
} | |
} | |
int main(){ | |
string d; | |
getline(cin, d); | |
cout << d << endl; | |
rev(d); | |
cout << d << endl; | |
cin.get(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment