class Solution
{
    public:
    //Function to reverse words in a given string.
    string reverseWords(string S) 
    { 
        
        vector<string>v;
        string word="";
        for(auto x:S)
        {
            if(x=='.')
            {
                v.push_back(word);
                v.push_back(".");
                word="";
                continue;
            }
            word=word+x;
        }
        v.push_back(word);
        string s="";
        reverse(v.begin(),v.end());
        for(auto x:v)
        {
            s.append(x);
        }
        return s;
    } 
};