최댓값

 

2566번: 최댓값

첫째 줄에 최댓값을 출력하고, 둘째 줄에 최댓값이 위치한 행 번호와 열 번호를 빈칸을 사이에 두고 차례로 출력한다. 최댓값이 두 개 이상인 경우 그 중 한 곳의 위치를 출력한다.

www.acmicpc.net

 

내 코드

const fs = require('fs');
let input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');
let N = 0;
let M = 0;
const arr = [];
input.forEach((i) => {
    i = i.split(' ').map(a=>Number(a));
    M = i.length;
    arr.push(...i);
});

const max = Math.max(...arr);
const index = arr.indexOf(max);
console.log(max)
console.log(Math.floor(index/M) +1 , index%M +1);
728x90

+ Recent posts