카타 8급 Twice as old

1 C++[ | ]

int twice_as_old(int dad, int son) {
  return abs(dad-son*2);
}

2 Kotlin[ | ]

fun twiceAsOld(dadYearsOld: Int, sonYearsOld: Int) = Math.abs(dadYearsOld - sonYearsOld * 2)
fun twiceAsOld(dadYearsOld: Int, sonYearsOld: Int) = if (dadYearsOld >= 2 * sonYearsOld) dadYearsOld - 2 * sonYearsOld else 2 * sonYearsOld - dadYearsOld
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}