Answers for "reverse each word seperated by "." in a string c++"

0

reverse each word seperated by "." in a string c++

string reverse(string &s)//this func reverses single words
    {
        string r;
        for(int i=s.size()-1;i>=0;i--)
        {
            r+=s[i];
        }
        return r;
    }
    //Function to reverse words in a given string.
    string reverseWords(string s) 
    { 
        // we are reversing eachword from the end adn adding
        string k,ans;
        for(int i=s.size()-1;i>=0;i--)
        {
            if(s[i]=='.')
            {
                k=reverse(k);
                ans+=k;ans+='.';
                k.clear();
                continue;
            }
            
            k+=s[i];
        }
        ans+=reverse(k);
        return ans;
    }
Posted by: Guest on August-16-2021

Code answers related to "reverse each word seperated by "." in a string c++"

Browse Popular Code Answers by Language