카타 8급 Cat years, Dog years

1 C++[ | ]

#include <vector>
std::vector<int> humanYearsCatYearsDogYears(int humanYears) {
  int catYears = (humanYears<3) ? 6+9*humanYears : 16+4*humanYears;
  int dogYears = (humanYears<3) ? 6+9*humanYears : 14+5*humanYears;
  return {humanYears, catYears, dogYears};
}
#include <vector>
std::vector<int> humanYearsCatYearsDogYears(int humanYears) {
  return { humanYears,
    (humanYears<3) ? 6+9*humanYears : 16+4*humanYears,
    (humanYears<3) ? 6+9*humanYears : 14+5*humanYears };
}
#include <vector>
std::vector<int> humanYearsCatYearsDogYears(int humanYears) {
  if (humanYears==1) return {1,15,15};
  if (humanYears==2) return {2,24,24};
  return {humanYears, 16+humanYears*4, 14+5*humanYears};
}

2 Kotlin[ | ]

package solution
fun calculateYears(years: Int): Array<Int> {
    val catYears = if(years<3) 6+9*years else 16+4*years
    val dogYears = if(years<3) 6+9*years else 14+5*years
    return arrayOf(years, catYears, dogYears)
}
package solution
fun calculateYears(years: Int): Array<Int> =
    when (years) {
        1 -> arrayOf(1, 15 , 15)
        2 -> arrayOf(years, 24 , 24)
        else -> arrayOf(years, 24 + 4 * (years - 2), 24 + 5 * (years - 2))
    }
package solution
fun calculateYears(years: Int): Array<Int> {
  return arrayOf(years,
      if(years<2) 15 else 4*years+16,
      if(years<2) 15 else 5*years+14)
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}