Sunday, August 1, 2021

reverse a string

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

Java Regex

You are updating the username policy on your company's internal networking platform. According to the policy, a username is considered v...