class Solution {
public:
    string trans(string s, int n) {
        reverse(s.begin(), s.end());
        int start = 0;
        auto blank = s.find(' ', start);
        while (blank != string::npos) {
            reverse(s.begin() + start, s.begin() + blank);
            start = blank + 1;
            blank = s.find(' ', start);
        }
        reverse(s.begin() + start, s.end());
        for_each(s.begin(), s.end(), [](auto &i) {
            if (i >= 'a' && i <= 'z') {
                i += 'A' - 'a';
            } else if (i >= 'A' && i <= 'Z') {
                i += 'a' - 'A';
            }
        });
        return s;
    }
};

思路:分为两步

1、反转字符串

2、反转每个字母字符