Created
July 8, 2015 14:31
-
-
Save marius92mc/8cf5e2f141e77d3316e7 to your computer and use it in GitHub Desktop.
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
/* | |
* ===================================================================================== | |
* | |
* Filename: reverse_string_stl.cpp | |
* | |
* Description: | |
* | |
* Version: 1.0 | |
* Created: 03/04/2015 09:49:47 AM | |
* Revision: none | |
* Compiler: gcc/g++ | |
* | |
* Author: Marius-Constantin Melemciuc | |
* email: | |
* Organization: | |
* | |
* ===================================================================================== | |
*/ | |
#include <cstdio> | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
void swap(char& a, char& b) { | |
a = a ^ b; | |
b = a ^ b; | |
a = a ^ b; | |
} | |
void reverseString(string& str) { | |
int str_length = str.length(); | |
for (int i = 0; i < (str_length >> 1); i++) | |
swap(str[i], str[str_length - i - 1]); | |
} | |
/* | |
void reverseArray(vector<int>& array) { | |
int n = array.size(); | |
for (int i = 0; i < (n >> 1); i++) { | |
swap(array[i], array[n - i - 1]); | |
} | |
} | |
*/ | |
int main(int argc, char** argv) { | |
string s; | |
cin >> s; | |
reverseString(s); | |
cout << s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment