๊ด€๋ฆฌ ๋ฉ”๋‰ด

\(@^0^@)/

[JS] ๋ฐฑ์ค€ 2884๋ฒˆ ์•Œ๋žŒ ์‹œ๊ณ„ ๋ณธ๋ฌธ

์•Œ๊ณ ๋ฆฌ์ฆ˜

[JS] ๋ฐฑ์ค€ 2884๋ฒˆ ์•Œ๋žŒ ์‹œ๊ณ„

minjuuu 2021. 9. 16. 18:05
728x90

๐Ÿฑ‍๐Ÿ‘“ 1. ๋ฌธ์ œ : 2884

https://www.acmicpc.net/problem/2884


๐Ÿ”ฅ 2. ์ฝ”๋“œ ๊ฒธ ํ’€์ด

const fs = require('fs');
const file = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let input = fs.readFileSync(file).toString().split('\n');

input = input[0];
input = input.split(' ').map((item) => Number(item));

solution(input[0], input[1]);

function solution(H, M) {

  // 45๋ถ„ ์ผ์ฐ ์•Œ๋žŒ ์„ค์ •
  // M = M - 45;
  M -= 45;

  // ๋งŒ์•ฝ 45๋ถ„์„ ๋นผ์„œ -๊ฐ€ ๋œ๋‹ค๋ฉด
  if(M < 0){
    
    // ๋ถ„์— 60๋ถ„์„ ๋”ํ•˜๊ณ , ์‹œ์— -1

    // M += 60;
    M = M + 60;
    H --;

    // ๋งŒ์•ฝ H๊ฐ€ -1 ์ด๋ผ๋ฉด, ๊ทธ ์ „๋‚ ์ธ 23์‹œ๋กœ ๋ณ€๊ฒฝ
    if (H === -1){
      H = 23;
    }
  }
  console.log(H+ ' ' + M);
}

โšก 3. ๋Š๋‚€ ์ ?

์˜ˆ์‹œ ์ฝ”๋“œ๋ฅผ ๋„ฃ์–ด๋ณด๋ฉด ๊ฒฐ๊ด๊ฐ’์ด ๋ชจ๋‘ ์•Œ๋งž๊ฒŒ ๋‚˜์˜ค๋Š”๋ฐ, ๋ญ๊ฐ€ ๋ฌธ์  ์ง€ ์ œ์ถœํ•ด๋ณด๋ฉด ์ •๋‹ต์€ ์•„๋‹ˆ๋ผ๊ณ  ๋œธใ…œ.ใ…œ
๊ทธ๋ž˜์„œ ๊ณ„์†ํ•ด๋ณด๋‹ค๊ฐ€, ๊ฒฐ๊ตญ ๊ตฌ๊ธ€๋ง ํ•ด์„œ ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ์ฝ”๋“œ๋ฅผ ๋ณด์•˜๋‹ค.
๋‚˜๋Š” ์—„์ฒญ ํ’€์–ด์„œ ์ผ๋Š”๋ฐ, ์ด ๋ถ„์€ -=, -- ์ด์šฉํ•ด์„œ ์—„์ฒญ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์ฝ”๋”ฉํ•˜์‹ฌ. ๋ณด๊ณ  ๋ฐฐ์šฐ์ž!
๋‚˜๋„ ๋‹ค์Œ๋ฒˆ์—” console์„ ๋ฐ‘์—์„œ ์ฐ์–ด๋ณด์ž.


โ€ป ํ’€์ด ์ฐธ๊ณ  : https://gurtn.tistory.com/20

728x90