题目传送门
思路
直接模拟即可,根据题目,需要做如下操作:
- 遍历字符串,对于 ,如果其为小写字母(
islower(s[i])),则转大写,反之转小写字母。 - 删去元音字母(
a,e,i,o,u和A,E,I,O,U)。 - 反转字符串。
代码
#include <bits/stdc++.h>
using namespace std;
bool chk(char c) {
return c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U';
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
string ans;
for (char c : s) {
if (chk(c)) continue;
if (islower(c)) {
ans += toupper(c);
} else if (isupper(c)) {
ans += tolower(c);
}
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}