카타 7급 Simple Fun #74: Growing Plant

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:55 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

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