카타 8급 I love you, a little , a lot, passionately ... not at all

Jmnote bot (토론 | 기여)님의 2019년 2월 3일 (일) 04:03 판 (봇: 자동으로 텍스트 교체 (-분류:PHP +))

1 개요

카타 8급 C
# 🔗 문제 풀이

틀:카타 8급-34

2 C++

std::string how_much_i_love_you(int nb_petals) {
  switch(nb_petals%6) {
    case 1: return "I love you";
    case 2: return "a little";
    case 3: return "a lot";
    case 4: return "passionately";
    case 5: return "madly";
    case 0: return "not at all";
  }
}
std::string how_much_i_love_you(int nb_petals) {
    string arr[] = {"I love you", "a little", "a lot", "passionately", "madly", "not at all"};
    return arr[(nb_petals - 1) % 6];
}

3 PHP

function how_much_i_love_you(int $nb_petals): string {
  switch($nb_petals%6) {
    case 1: return 'I love you';
    case 2: return 'a little';
    case 3: return 'a lot';
    case 4: return 'passionately';
    case 5: return 'madly';
    case 0: return 'not at all';
  }
}
function how_much_i_love_you(int $nb_petals): string {
  return ["I love you", "a little", "a lot", "passionately", "madly", "not at all"][($nb_petals - 1) % 6];
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}