728x90

Code

😢 변의 길이 순서가 랜덤으로 들어오는 듯 하다.
😊 ||(or)으로 모든 경우를 넣어주든지
sort로 순서를 처리해주면 된다.
Full Code (https://github.com/DasolPark/Dasol_JS_Algorithm/tree/master/Baekjoon)
| // A right-angled triangle(Pythagorean theorem) |
| // 2nd Soludion(sort) |
| // For submit |
| // const fs = require('fs'); |
| // const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n'); |
| // For local test |
| const input = ['6 8 10', '25 52 60', '5 12 13', '5 4 3', '0 0 0']; |
| for (let sides of input) { |
| const strToInt = sides |
| .split(' ') |
| .map(num => Math.pow(parseInt(num), 2)) |
| .sort((a, b) => a - b); |
| const firstSidePow = strToInt.shift(); |
| const secondSidePow = strToInt.shift(); |
| const thirdSidePow = strToInt.shift(); |
| if (firstSidePow === 0 && secondSidePow === 0 && thirdSidePow === 0) { |
| break; |
| } |
| if (firstSidePow + secondSidePow === thirdSidePow) { |
| console.log('right'); |
| } else { |
| console.log('wrong'); |
| } |
| } |
| // 1st Solution(or) |
| // For submit |
| // const fs = require('fs'); |
| // const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n'); |
| // For local test |
| // const input = ['6 8 10', '25 52 60', '5 12 13', '0 0 0']; |
| // for (let sides of input) { |
| // const strToInt = sides.split(' ').map(num => Math.pow(parseInt(num), 2)); |
| // const firstSidePow = strToInt.shift(); |
| // const secondSidePow = strToInt.shift(); |
| // const thirdSidePow = strToInt.shift(); |
| // if (firstSidePow === 0 && secondSidePow === 0 && thirdSidePow === 0) { |
| // break; |
| // } |
| // if ( |
| // firstSidePow + secondSidePow === thirdSidePow || |
| // firstSidePow + thirdSidePow === secondSidePow || |
| // secondSidePow + thirdSidePow === firstSidePow |
| // ) { |
| // console.log('right'); |
| // } else { |
| // console.log('wrong'); |
| // } |
| // } |
'Algorithm > JavaScript(Node.js)' 카테고리의 다른 글
| 백준 3053번: 택시 기하학(유클리드 기하학) Node.js(JavaScript) (0) | 2020.01.28 |
|---|---|
| 백준 3009번: 네 번째 점(직사각형) Node.js(JavaScript) (0) | 2020.01.27 |
| 백준 1085번: 직사각형에서 탈출 Node.js(JavaScript) (0) | 2020.01.25 |
| 백준 9020번: 소수 구하기(골드바흐의 추측 - 에라토스테네스의 체) Node.js(JavaScript) (0) | 2020.01.24 |
| 백준 4948번: 소수 구하기(베르트랑 공준 - 에라토스테네스의 체) Node.js(JavaScript) (0) | 2020.01.22 |