์๊ณ ๋ฆฌ์ฆ
[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