Programming/백준
[백준] 2562번 : 최댓값
조용한고라니
2021. 5. 1. 19:56
반응형
2562번: 최댓값
9개의 서로 다른 자연수가 주어질 때, 이들 중 최댓값을 찾고 그 최댓값이 몇 번째 수인지를 구하는 프로그램을 작성하시오. 예를 들어, 서로 다른 9개의 자연수 3, 29, 38, 12, 57, 74, 40, 85, 61 이 주어
www.acmicpc.net
[배열]
Javascript로 문제풀이를 익히기 위해 풀어본 문제.
# Code </>
const readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var arr = [];
rl.on('line', (input)=>{
arr.push(input);
}).on('close', ()=>{
var max=0, maxIdx=0;
arr.forEach((num, idx) => {
if(num > max){
max = parseInt(num);
maxIdx = (idx + 1);
}
});
console.log(max);
console.log(maxIdx);
});
반응형