BJ-2839-설탕 배달

이은지·2023년 1월 16일
0

코딩테스트

목록 보기
64/76

문제
https://www.acmicpc.net/problem/2839

풀이

let input = require('fs').readFileSync('/dev/stdin');
let count = 0;
while (input > 0) {
  if (input % 5 === 0) {
    input -= 5;
  } else {
    input -= 3;
  }
  count += 1;
}
input === 0 ? console.log(count) : console.log(-1);

마무리

while문을 많이 안써봐서 할때마다 새로운데 활용을 자주하면서 익숙해져야겠다.

0개의 댓글