최댓값
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
'Algorithm&CodingTest > Baekjoon' 카테고리의 다른 글
[Baekjoon] [1978] 실버4 - 소수찾기 (0) | 2023.02.24 |
---|---|
[Baekjoon] [2754] 학점 계산 (0) | 2023.02.24 |
[Baekjoon] [1371] 가장 많은 글자 (0) | 2023.02.24 |
[Beakjoon] [1427] 정렬 - 소트인사이드 (0) | 2023.02.24 |
[Baekjoon] [11650] 실버5 - 좌표 정렬하기 NodeJs (0) | 2023.02.24 |