C++ 字符串处理:删除相邻元音
#include
using namespace std;
int main() {
int n;
string s;
unordered_set
cin >> n >> s;
for (int i = 0; i < n; i++) {
if (vowels.count(s[i])) { // 如果当前字符是元音
cout << s[i]; // 输出该元音
while (i < n - 1 && vowels.count(s[i + 1])) { // 将相邻的元音删掉
i++;
}
} else { // 如果不是元音
cout << s[i]; // 直接输出
}
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/m51i 著作权归作者所有。请勿转载和采集!