https://www.acmicpc.net/problem/2562
my attempt
function findMax(arr) {
const maxResult = Math.max(...arr);
console.log(maxResult);
const el = arr.indexOf(maxResult);
console.log(el + 1);
}
findMax([3, 29, 38, 12, 57, 74, 40, 85, 61]);
others
const input = require("fs").readFileSync("/dev/stdin").toString().split("\n");
const inputToInt = input.map((num) => (num = parseInt(num)));
let max = 0;
let idx = 0;
for (let i = 0; i < inputToInt.length; i++) {
if (inputToInt[i] > max) {
max = inputToInt[i];
idx = i + 1;
}
}
console.log(max);
console.log(idx);
Comments
Post a Comment