考虑直接模拟,用一个 for 循环去找,从某个字符 c = s[i] 开始,一直减一,直到找到某个元音字母就停止并输出这个字母即可。

#include<cstdio>
#include<cstring>
const int N = (int) 1e6 + 5;
char s[N];
int main(){
    while (scanf("%s", s + 1) != EOF) {
        int len = strlen(s + 1);
        for (int i = 1; i <= len; ++i) {
            char c;
            for (c = s[i]; c >= 'a'; --c) {
                if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y')
                    break;
            }
            putchar(c);
        }
        putchar('\n');
    }
}