Skip to content

Instantly share code, notes, and snippets.

@marius92mc
Created July 8, 2015 14:31
Show Gist options
  • Save marius92mc/8cf5e2f141e77d3316e7 to your computer and use it in GitHub Desktop.
Save marius92mc/8cf5e2f141e77d3316e7 to your computer and use it in GitHub Desktop.
/*
* =====================================================================================
*
* 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