You are given a string s. You need to reverse the string.
Example 1:
Input:
s = Geeks
Output: skeeG#include<bits/stdc++.h>
using namespace std;
string reverseWord(string str);
int main() {
int t;
cin>>t;
while(t--)
{
string s;
cin >> s;
cout << reverseWord(s) << endl;
}
return 0;
}
// } Driver Code Ends
//User function Template for C++
string reverseWord(string str){
int len = str.length()-1;
int i=0;
while(i<len)
{
char c = str[i];
str[i] = str[len];
str[len] = c;
i++;
len--;
}
return str;
}
No comments:
Post a Comment