SMALL

const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let sugar = Number(fs.readFileSync(filePath).toString());
solution();
function solution() {
let smallBag = 0;
while (true) {
if (sugar % 5 == 0) {
console.log(sugar / 5 + smallBag);
break;
} else if (sugar / 5 < 0) {
console.log(-1);
break;
} else {
sugar -= 3;
smallBag++;
}
}
}
sugar % 5 == 0 이 아닐 경우 ( 5kg이 커야 봉지 개수가 적어지는데 5의 배수가 아닐경우)
sugar -= 3
smallBag++; 을 해줌으로서 3kg가방을 하나 추가하고 다시 5의 배수체크하러감
while(true)에서 true말고 다른게 있는지 모르겠음
그래서 break를 잊지말고하기
LIST
'코테 > 코테withJS' 카테고리의 다른 글
| 백준 Node.js(자바스크립트) 2446문제 별찍기 -9 (0) | 2021.09.20 |
|---|---|
| 백준 Node.js(자바스크립트) 1011문제 Fly me to the Alpha Centauri (0) | 2021.09.10 |
| 백준 Node.js(자바스크립트) 2869번 달팽이올라가는 문제 (0) | 2021.08.29 |
| 백준 Node.js(자바스크립트) 1712번 손익분기점 문제 (0) | 2021.08.20 |
| Node.js로 백준문제풀기 런타임에러(runtime error) (0) | 2021.08.06 |