카타 8급 101 Dalmatians - squash the bugs, not the dogs!

1 C++[ | ]

std::string howManyDalmatians(int number)
{
  if( number < 11 ) return "Hardly any";
  if( number < 51 ) return "More than a handful!";
  if( number < 101 ) return "Woah that's a lot of dogs!";
  return "101 DALMATIONS!!!";
}

2 PHP[ | ]

function howManyDalmations($number) {
  $dogs = ["Hardly any", "More than a handful!", "Woah that's a lot of dogs!", "101 DALMATIANS!!!"];
  $respond = $number <= 10 ? $dogs[0] : ($number <= 50 ? $dogs[1] : ($number == 101 ? $dogs[3] : $dogs[2]));
  return $respond;
}
function howManyDalmations($number){
  $dogs = ["Hardly any", "More than a handful!", "Woah that's a lot of dogs!", "101 DALMATIANS!!!"];
  if($number <= 10) return $dogs[0];
  if($number <= 50) return $dogs[1];
  if($number <= 100) return $dogs[2];
  if($number >= 101) return $dogs[3];
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}