카타 7급 Simple Fun #74: Growing Plant

1 Kotlin[ | ]

2 R[ | ]

growing_plant <- function(up_speed, down_speed, height) {
  if (height <= up_speed) return(1)
  (height - up_speed) %/% ( up_speed - down_speed) + 1 + 1 * ((height - up_speed) %% ( up_speed - down_speed) != 0)
}
growing_plant <- function(up_speed, down_speed, height) {
  if (height <= up_speed) return(1)
  res = (height-up_speed) %/% (up_speed-down_speed) + 1
  if( (height-up_speed) %% (up_speed-down_speed) == 0 ) res else res+1
}
growing_plant <- function(up_speed, down_speed, height) {
  h = 0
  cnt = 1
  while( TRUE ) {
    h = h + up_speed
    if( h >= height ) return(cnt)
    h = h - down_speed
    cnt = cnt + 1
  }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}