class Solution {
public:
string trans(string s, int n) {
// write code here
// 两次翻转
reverse(s.begin(), s.end());
for(int i = 0; i < n; i++) {
int j = i;
while(s[i] != '\0' && s[i] != ' ') {
if('a' <= s[i] && s[i] <= 'z')
s[i] = 'A' + s[i] - 'a';
else if('A' <= s[i] && s[i] <= 'Z')
s[i] = 'a' + s[i] - 'A';
i++;
}
reverse(s.begin() + j, s.begin() + i);
}
return s;
}
};