题解 | #字符串变形#
字符串变形
https://www.nowcoder.com/practice/c3120c1c1bc44ad986259c0cf0f0b80e
class Solution {
public:
string trans(string s, int n) {
string tmp = "", res = "";
for (int i = 0; i < n; i++) {
if (s[i] == ' ') {
res = tmp + " " + res; //倒序
tmp = "";
} else {
tmp += s[i] > 90 ? s[i] - 32 : s[i] + 32; //反转大小写
}
}
res = tmp + " " + res;
res.erase(res.end() - 1);
return res;
}
};

