xxxxxxxxxx
#include <iostream>
#include <string>
using namespace std;
void REVERSE(string word){
string reversed = word;
int n = word.length();
int t = 0;
for (int i = n - 1;i >= 0; i--) {
reversed[t++] = word[i];
}
cout << reversed << "\n\n";
if(word==reversed)
cout<<"Palindrome";
else cout<<"not palindrome";
}
int main(){
string text;
cout<<"Enter text: ";
getline(cin,text);
REVERSE(text);
}
xxxxxxxxxx
#include <algorithm>
#include <iostream>
#include <string>
int main()
{
std::string foo("foo");
std::string copy(foo);
std::cout << foo << '\n' << copy << '\n';
std::reverse(copy.begin(), copy.end());
std::cout << foo << '\n' << copy << '\n';
}
xxxxxxxxxx
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str;
getline(cin,str);
reverse(str.begin(),str.end());
cout<<str;
}
xxxxxxxxxx
// C++ function to reverse string str:
string rev = string(str.rbegin(), str.rend());
xxxxxxxxxx
string reverse(string str)
{
string output;
for(int i=str.length()-1; i<str.length(); i--)
{
output += str[i];
}
return output;
}
xxxxxxxxxx
#include <iostream>
//The library below must be included for the reverse function to work
#include<bits/stdc++.h>
using namespace std;
int main() {
string greeting = "Hello";
//Note that it takes the iterators to the start and end of the string as arguments
reverse(greeting.begin(),greeting.end());
cout<<greeting<<endl;
}
xxxxxxxxxx
// C++ program to illustrate the
// reversing of a string using
// reverse() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str = "geeksforgeeks";
// Reverse str[begin..end]
reverse(str.begin(), str.end());
cout << str;
return 0;
}
xxxxxxxxxx
#include <iostream>
#include <cstring>
using namespace std;
void palindrome(string word){
string reversed=word;
for (int i = 0, j = word.length() - 1; i < word.length(), j >= 0; i++, j--) {
reversed[j] = word[i];
}
cout<< reversed<<endl;
if(word==reversed)
cout<<"Palindrome";
else cout<<"not palindrome";
}
int main(){
string text;
cout<<"Enter text: ";
getline(cin,text);
reverse(text);
}
xxxxxxxxxx
#include <iostream>
#include <string>
using namespace std;
void REVERSE(string word){
string reversed = word;
int n = word.length();
int t = 0;
for (int i = n - 1;i >= 0; i--) {
reversed[t++] = word[i];
}
cout << reversed << "\n\n";
if(word==reversed)
cout<<"Palindrome";
else cout<<"not palindrome";
}
int main(){
string text;
cout<<"Enter text: ";
getline(cin,text);
REVERSE(text);
}
xxxxxxxxxx
#include <iostream>
#include <string>
void swapChars(char* x, char* y) {
char temp = *x;
*x = *y;
*y = temp;
}
//raw is the input string
std::string reverseString(std::string raw) {
int n = raw.length();
//keep swapping front end chars with
//their back end counterparts till you
//get to the middle of the string
for (int i = 0; i < n / 2; i++)
swapChars(&raw[i], &raw[n-i-1]);
return raw;
}
int main() {
std::string input;
std::cin >> input;
std::cout << reverseString(input) << "\n";
return 0;
}