// https://bbc3502.hopto.org/c2021/index.php/home-17/590-3 #include //将只包含小写字母的字符串str中的元音字母复制到字符数组vowel,并返回元音字符的个数。 int getVowel(char str[], char vowel[]); int main() { char vowel[101], str[101]; //每个数组都至少要101个字节 int len; scanf("%s", str); //读入字符串 len = getVowel(str, vowel); //复制 if (len > 0) printf("%d %s\n", len, vowel); //输出复制后结果 else printf("%d\n", len); //仅输出长度 return 0; } /* 请在这里填写答案 */ #include #pragma GCC optimize("Ofast,inline") int getVowel(char str[], char vowel[]) { char vowelstr[] = {'a', 'e', 'i', 'o', 'u'}; int len = 0; for (int i = 0, n = strlen(str); i < n; i++) { for (int j = 0, m = sizeof(vowelstr) / sizeof(char); j < m; j++) { if (vowelstr[j] == str[i]) { vowel[len++] = str[i]; } } } // vowel[len] is a trash value, and will lead to undefined behavior in some // cases vowel[len] = '\0'; return len; }