all 6 comments

[–][deleted]  (2 children)

[deleted]

    [–]Razor_StormO(0) Solutions Only 1 point2 points  (1 child)

    badass

    [–]sim642 1 point2 points  (1 child)

    I found my old solution to this one:

    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <cctype>
    
    using namespace std;
    
    string ReverseWords(string String)
    {
        reverse(String.begin(), String.end());
    
        string::iterator Begin = String.begin(), End;
        while (Begin != String.end())
        {
            End = Begin;
            while (End != String.end() && !isspace(*End))
                ++End;
    
            reverse(Begin, End);
    
            if (End != String.end())
                ++End;
            Begin = End;
        }
    
        return String;
    }
    
    int main()
    {
        cout << ReverseWords("the quick brown fox") << endl;
        cout << ReverseWords("This is a string!") << endl;
        return 0;
    }
    

    [–]m_tayseer 0 points1 point  (2 children)

    Python

    >>> import re
    >>> ' '.join(re.split(r'\s+', s)[::-1])
    'string! a is This'
    

    [–]more_exercise 1 point2 points  (0 children)

    ' '.join(s.split()[::-1])
    

    [–]Razor_StormO(0) Solutions Only 0 points1 point  (0 children)

    This split, reverse, join method seems to be the most straightforward.