티스토리 뷰
728x90
문제 링크
https://www.acmicpc.net/problem/25285
25285번: 심준의 병역판정검사
병역판정검사는 병역의무자들의 상태를 검사해 징병 여부와 징병 시 어느 방향으로 복무를 시키는 게 좋을지 판정하는 검사로, 남성들은 만 19세가 되는 해에 모두 병역판정검사를 받는다. 신체
www.acmicpc.net
풀이
여러 개의 조건문을 이용하여 풀어주면 됩니다.
저 같은 경우는 명확히 키만으로 급수가 나오는 경우를 classifyWithHeight() 함수로, 그 외의 경우를 classifyWithBMI() 함수로 빼서 판단했습니다.
정답 코드
// @BOJ ------------------------------------------ const fs = require('fs'); const stdin = fs.readFileSync('/dev/stdin').toString().split('\n'); const input = (() => { let line = 0; const input = () => stdin[line++]; input.num = () => input().split(' ').map(Number); input.rows = l => Array(l).fill().map(input); input.rows.num = l => Array(l).fill().map(input.num); return input; })(); // Solution ----------------------------------- const square = num => num * num; const isInRange = value => (l, r) => l <= value && value < r; const calcBMI = (height, weight) => weight / square(height / 100); const classifyWithHeight = height => { if (height < 140.1) return 6; else if (height < 146) return 5; else if (height < 159 || height >= 204) return 4; else return -1; }; const classifyWithBMI = (height, weight) => { const isBMIInRange = isInRange(calcBMI(height, weight)); if (!isBMIInRange(16, 35)) return 4; else if (isInRange(height)(159, 161)) return 3; else if (isBMIInRange(16, 18.5) || isBMIInRange(30, 35)) return 3; else if (isBMIInRange(18.5, 20) || isBMIInRange(25, 30)) return 2; else return 1; }; const classify = ([height, weight]) => { const classification = classifyWithHeight(height); if (classification < 0) return classifyWithBMI(height, weight); return classification; }; const solution = function () { const t = +input(); const ans = input.rows.num(t).map(classify).join('\n'); console.log(ans); }; solution();
728x90
'알고리즘 > 문제 풀이' 카테고리의 다른 글
BOJ 25287 - 순열 정렬 (Javascript) (0) | 2022.06.19 |
---|---|
BOJ 25286 - 11월 11일 (Javascript) (0) | 2022.06.19 |
[BOJ] 백준 22983 - 조각 체스판 (SUAPC 2021 Summer) (0) | 2021.09.12 |
[BOJ] 백준 22991 - 수요응답형 버스 (SUAPC 2021 Summer) (0) | 2021.09.12 |
[BOJ] 백준 4828 - XML (0) | 2021.08.15 |
댓글