카타 8급 Exclamation marks series #11: Replace all vowel to exclamation mark in the sentence

1 C[ | ]

char *replace(const char *s) {
  char *res = strdup(s);
  for(char *p=res; *p; p++) {
    if( strchr("aeiouAEIOU", *p) ) *p = '!';
  }
  return res;
}
char *replace(const char *s) {
  char *res = strdup(s);
  for(char *p = res; *p; p++) {
    switch(tolower(*p)) {
      case 'a':
      case 'e':
      case 'i':
      case 'o':
      case 'u':
        *p = '!';
    }
  }
  return res;
}
char *replace(const char *s) {
  int len = strlen(s);
  char *res = calloc(len+1, sizeof(char));
  strcpy(res, s);
  for(int i=0; i<len; i++) {
    switch(tolower(res[i])) {
      case 'a':
      case 'e':
      case 'i':
      case 'o':
      case 'u':
        res[i] = '!';
    }
  }
  return res;
}

2 C++[ | ]

#include <regex>
using namespace std;
string replace(const string &s)
{
  return regex_replace(s, regex("[aeiouAEIOU]"), "!");
}
using namespace std;
string replace(string s) {
  string vowels = "aeiouAEIOU";
  for (auto& c : s) if (vowels.find(c) != string::npos) c = '!';
  return move(s);
}
using namespace std;
string replace(const string &s)
{
    string res = s;
    replace_if(res.begin(), res.end(), [](char c){
      return (toupper(c) == 'A' || 
        toupper(c) == 'E' ||
        toupper(c) == 'O' ||
        toupper(c) == 'I' ||
        toupper(c) == 'U');}, '!');
    return res;
}
using namespace std;
string replace(const string &s)
{
  string res = s;
  replace(res.begin(), res.end(), 'a', '!');
  replace(res.begin(), res.end(), 'e', '!');
  replace(res.begin(), res.end(), 'i', '!');
  replace(res.begin(), res.end(), 'o', '!');
  replace(res.begin(), res.end(), 'u', '!');
  replace(res.begin(), res.end(), 'A', '!');
  replace(res.begin(), res.end(), 'E', '!');
  replace(res.begin(), res.end(), 'I', '!');
  replace(res.begin(), res.end(), 'O', '!');
  replace(res.begin(), res.end(), 'U', '!');
  return res;
}

3 Kotlin[ | ]

fun replace(s: String): String = s.replace("[aeiouAEIOU]".toRegex(), "!")
fun replace(s: String): String = s.replace(Regex("a|e|i|o|u", RegexOption.IGNORE_CASE), "!")
fun replace(s: String): String = "[aeiou]".toRegex(RegexOption.IGNORE_CASE).replace(s, "!")

4 PHP[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}