[백준25314_자바스크립트(javascript)] - 코딩은 체육과목 입니다

경이·2024년 8월 20일

𝑩𝑶𝑱 (𝒋𝒔)

목록 보기
149/325

🔴 문제

코딩은 체육과목 입니다


🟡 Sol

const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : 'Wiki\\input.txt';
let n = Number(fs.readFileSync(path));

let ans = '';
while (true) {
  if (n === 0) {
    ans += 'int';
    break;
  } else {
    ans += 'long';
    n -= 4;
  }
  ans += ' ';
}

console.log(ans);

🟢 풀이

⏰ 소요한 시간 : -

무한반복을 하면서 n0이 될 때까지 4씩 빼면서 long을 출력하면 된다.
n0이되는순간 int를 출력해줘야 하는데 혹시 몰라서 ans 문자열에 더해 한번의 콘솔만 찍히게 했다.


🔵 Ref

profile
록타르오가르

0개의 댓글