classSolution { public: voidreverse(string& s, int i, int j){ while (i < j) { swap(s[i++], s[j--]); } }
stringtrans(string s, int n){ int begin = 0; for (int i = 0; i < s.length();) { if (s[i] == ' ') { reverse(s, begin, i - 1); i++; begin = i; } else { i++; } } reverse(s, begin, s.length() - 1);