목록직사각형과삼각형 (8)
언젠가는 펼쳐 볼 아카이브

사용언어 : javascript - node.js #문제 #접근방법 삼각형에서 제일 긴 변의 길이가 나머지 두 변의 길이보다 작으면 삼각형이 된다. 만약에 위의 조건을 만족하지 않을 경우, 막대 길이를 늘리거나 줄여서 가장 큰 둘레를 구해야한다 그럼 얼마나 줄이고 얼마나 늘려야하나..? 고민해봤는데 제일 큰 변을 제외한 나머지 두 변의 길이의 합보다 -1만 작으면 최대 둘레가 된다. 굿. #제출코드 const fs = require('fs'); const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; const arr = fs .readFileSync(filePath) .toString() .trim() .split(' '..

사용언어 : javascript - node.js #첫번째 제출코드 const fs = require('fs'); const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; const input = fs .readFileSync(filePath) .toString() .trim() .split('\n') .map((item) => item .trim() .split(' ') .map((item) => +item) ); input.forEach((item) => { if (item[0] !== 0 && item[2] !== 0) { solution(item); } }); function solution(item) { item...
사용언어 : javascript - node.js #제출코드 const fs = require('fs'); const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; const input = fs .readFileSync(filePath) .toString() .trim() .split('\n') .map((item) => +item); solution(input); function solution(input) { let sum = input.reduce((total, angle) => (total += angle)); if (input[0] === 60 && input[1] === 60 && input[2] === 60) ..

사용언어 : javascript - node.js #문제 #접근방법 최소 크기의 직사각형 넓이를 구해야한다. 처음엔 입력값의 좌표들이 담긴 사각형의 좌표를 하나하나 구해야 하나 했었는데, 생각해보니 그냥 그 좌표들을 가지고 사각형을 그려서 가로/세로 넓이를 구하면 될 것 같다. 그렇다면 점의 개수가 1개 일때는 넓이를 구할 수 없으므로 결과 값을 0으로 해주고, 점의 개수가 1개 이상일 때의 가로/세로 길이를 구해보자..! * 가로 길이 : x 좌표에서 제일 큰 값 - x 좌표에서 제일 작은 값 * 세로 길이 : y 좌표에서 제일 큰 값 - y 좌표에서 제일 작은 값 위와 같으므로 입력한 x좌표들과 y 좌표들을 내림차순으로 sort 한 후 길이를 계산해주자. 내림차순으로 정렬한 후 뺄셈을 했지만 혹시 모..