카타 7급 Vowel Count

1 C[ | ]

#include <stddef.h>
size_t get_count(const char *s)
{
  size_t cnt = 0ul;
  if (!s) return 0ul;
  while (*s) {
    switch (*s++) {
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
      cnt++;
    }
  }
  return cnt;
}
#include <stddef.h>
size_t get_count(const char *s)
{
  size_t cnt = 0;
  for(char *p=s; *p; p++) {
    if(*p=='a' || *p=='e' || *p=='i' || *p=='o' || *p=='u' ) cnt++;
  }
  return cnt;
}

2 Kotlin[ | ]

3 R[ | ]

get_count <- function(input_str){
  nchar(gsub("[^aeiou]", "", input_str))
}
get_count <- function(input_str){
  v = unlist(strsplit(input_str,""))
  sum(v %in% c("a","e","i","o","u"))
}
get_count <- function(input_str){
  v = strsplit(input_str,"")[[1]]
  length(v[v=="a"|v=="e"|v=="i"|v=="o"|v=="u"])
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}