[백준2566_자바스크립트(javascript)] - 최댓값

경이·2024년 9월 26일

𝑩𝑶𝑱 (𝒋𝒔)

목록 보기
187/325

🔴 문제

최댓값


🟡 Sol

const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : 'input.txt';
const inputs = fs
  .readFileSync(path)
  .toString()
  .trim()
  .split('\n')
  .map((it) => it.split(' '))
  .flat()
  .map(Number);

const max = Math.max(...inputs);
const idx = inputs.indexOf(max);
console.log(max);
console.log(Math.floor(idx / 9) + 1, (idx % 9) + 1);

🟢 풀이

⏰ 소요한 시간 : -

배열을 flat 하여 1차원 배열롭 변경한 뒤 max값을 찾는다. 그 후 그 max값이 몇번 인덱스를 가지고 있는지 idx값을 찾아준다.

행과 열이 9와 9로 정해져 있기 때문에 최대값을 출력하고 행은 idx를 9로 나눈 값을 내림한 뒤 1 을 더해주면 되고 열은 9로 나눈 나머지 더하기 1을 해주면묀다.


🔵 Ref

profile
록타르오가르

0개의 댓글