"카타 8급 I love you, a little , a lot, passionately ... not at all"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 7개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
{{카타 헤더}}
{{카타 8급-34}}
|}
==C==
==C==
[[분류: 카타 8급 C]]
{{카타|8급|C|7}}
<source lang='C'>
<syntaxhighlight lang='C'>
</source>
#include <stddef.h>
const char* 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";
  }
  return "";
}
</syntaxhighlight>
<syntaxhighlight lang='c'>
#include <stddef.h>
const char* how_much_i_love_you(int nb_petals) {
  const char *phrases[6] = {
    "I love you",
    "a little",
    "a lot",
    "passionately",
    "madly",
    "not at all"
  };
  return phrases[(nb_petals - 1) % 6];
}
</syntaxhighlight>


==C++==
==C++==
<source lang='cpp'>
{{카타|8급|C++|6}}
<syntaxhighlight lang='cpp'>
std::string how_much_i_love_you(int nb_petals) {
std::string how_much_i_love_you(int nb_petals) {
   switch(nb_petals%6) {
   switch(nb_petals%6) {
21번째 줄: 43번째 줄:
   }
   }
}
}
</source>
</syntaxhighlight>
<source lang='cpp'>
<syntaxhighlight lang='cpp'>
std::string how_much_i_love_you(int nb_petals) {
std::string how_much_i_love_you(int nb_petals) {
     string arr[] = {"I love you", "a little", "a lot", "passionately", "madly", "not at all"};
     string arr[] = {"I love you", "a little", "a lot", "passionately", "madly", "not at all"};
     return arr[(nb_petals - 1) % 6];
     return arr[(nb_petals - 1) % 6];
}
}
</source>
</syntaxhighlight>


==PHP==
==PHP==
<source lang='php'>
{{카타|8급|PHP|7}}
<syntaxhighlight lang='php'>
function how_much_i_love_you(int $nb_petals): string {
function how_much_i_love_you(int $nb_petals): string {
   switch($nb_petals%6) {
   switch($nb_petals%6) {
41번째 줄: 64번째 줄:
   }
   }
}
}
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
function how_much_i_love_you(int $nb_petals): string {
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];
   return ["I love you", "a little", "a lot", "passionately", "madly", "not at all"][($nb_petals - 1) % 6];
}
}
</source>
</syntaxhighlight>
 
[[분류:C++]]
 
[[분류:카타 8급 PHP]]

2020년 11월 2일 (월) 02:42 기준 최신판

1 C[ | ]

#include <stddef.h>
const char* 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";
  }
  return "";
}
#include <stddef.h>
const char* how_much_i_love_you(int nb_petals) {
  const char *phrases[6] = {
    "I love you",
    "a little",
    "a lot",
    "passionately",
    "madly",
    "not at all"
  };
  return phrases[(nb_petals - 1) % 6];
}

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 }}