문제 설명
영어에선 a, e, i, o, u 다섯 가지 알파벳을 모음으로 분류합니다. 문자열 my_string이 매개변수로 주어질 때 모음을 제거한 문자열을 return하도록 solution 함수를 완성해주세요.
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h> // Include for strlen and strchr function declarations
char* solution(const char* my_string) {
size_t len = strlen(my_string);
char* answer = (char*)malloc((len + 1) * sizeof(char)); // Allocate memory
int idx = 0;
for (size_t i = 0; i < len; i++) {
char current_char = my_string[i];
if (!strchr("aeiou", current_char)) {
answer[idx++] = current_char;
}
}
answer[idx] = '\0';
return answer;
}
'Coding Test' 카테고리의 다른 글
| 세균 증식 (0) | 2024.07.07 |
|---|---|
| 삼각형의 완성조건 (1) (0) | 2024.07.06 |
| 배열의 유사도 (0) | 2024.07.04 |
| 점의 위치 구하기 (0) | 2024.07.03 |
| 개미 군단 (0) | 2024.07.02 |