提交记录 #489
提交时间:2024-12-10 16:58:36
语言:c
状态:Unaccepted
编译情况:编译成功
固定测试点#1:
附加测试点暂不可用
58【应用】元音排序
#include <stdio.h>
#include <string.h>
#include <ctype.h>
// 判断字符是否为元音字母
int is_vowel(char c) {
c = tolower(c); // 统一转换为小写
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
// 对元音字符串进行排序
void sort_vowels(char *vowels, int length) {
for (int i = 0; i < length - 1; i++) {
for (int j = i + 1; j < length; j++) {
// 小写字母在前,大写字母在后
if (tolower(vowels[i]) > tolower(vowels[j]) ||
(tolower(vowels[i]) == tolower(vowels[j]) && vowels[i] > vowels[j])) {
char temp = vowels[i];
vowels[i] = vowels[j];
vowels[j] = temp;
}
}
}
}
// 提取并排序元音字母
void extract_and_sort_vowels(const char *input, char *output) {
int index = 0;
// 遍历输入字符串,提取元音字母
for (int i = 0; input[i] != '\0'; i++) {
if (is_vowel(input[i])) {
output[index++] = input[i];
}
}
output[index] = '\0'; // 添加字符串结束符
// 对提取的元音字母进行排序
sort_vowels(output, index);
}
int main() {
const char *input = "Abort!May Be Some Errors In Out System. ";
char output[100]; // 用于存储排序后的元音字母
// 提取并排序元音字母
extract_and_sort_vowels(input, output);
// 输出结果
printf("%s\n", output);
return 0;
}