algorithm - beakjoon 146881, 2525, 2884

박선우·2022년 8월 13일
0

알고리즘

목록 보기
14/15
post-thumbnail
  • beakjoon 알고리즘 146881, 2525, 2884 문제를 풀어봤다.

내가 푼 코드

  • 146881
const fs = require('fs');
const input = fs.readFileSync('./input.txt').toString().trim().split('\n').map(Number);

if (input[0] > 0 && input[1] > 0) {
    console.log(1);
} else if (input[0] < 0 && input[1] > 0) {
    console.log(2);
} else if (input[0] < 0 && input[1] < 0) {
    console.log(3);
}
console.log(4);
  • 2525
const input = require('fs').readFileSync('./input.txt').toString().split(' ').map(Number);

let [a, b, c] = input;

if (b + c >= 60) {
    const d = Math.floor((b + c) / 60); // 소수점 자리 버림
    b = (b + c) % 60; // 60으로 나눈 나머지 몫 67 % 60 = 6
    a = (a + d) % 24; // 24로 나눈 나머지 몫( a + d > 24 : 1 ? 0)
    console.log(a, b);
} else {
    console.log(a, b + c);
}
  • 2884
const input = require('fs').readFileSync('./input.txt').toString().split(' ').map(Number);

const [a, b] = input;

if (b > 45) {
    console.log(a, b - 45);
} else if (a < 0 && b < 45) {
    console.log(a - 1, 15 + b);
} else if (a < 0 && b > 45) {
    console.log(a, b - 45);
} else if (a === 0 && b < 45) {
    console.log(23, 15 + b);
}

더 좋은 정답 코드

  • 146881
if (input[0] > 0) {
    input[1] > 0 ? console.log(1) : console.log(4);
} else if (input[0] < 0) {
    input[1] > 0 ? console.log(2) : console.log(3);
}
  • 2884
const input = require('fs').readFileSync('./input.txt').toString().split(' ').map(Number);

const [a, b] = input;

if (0 < a && b < 45) {
    console.log(a - 1, b + 15);
} else if (a == 0 && b < 45) {
    console.log(23, b + 15);
} else {
    console.log(a, b - 45);
}
profile
코린이 열심히 배우자!

0개의 댓글