ํ”„์—” ๊ณต๋ถ€/๐Ÿซง ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ณต๋ถ€

[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ๋ฐฑ์ค€] node JS 2566 ์ตœ๋Œ“๊ฐ’

๋˜์ž๐Ÿ‹ 2023. 8. 19. 18:47
728x90

์•„ ๋„๋Œ€์ฒด ์™œ ํ‹€๋ ธ์ง€ ๋ถ„๋ช… ๋งž๋Š”๋ฐ ๋ผ๊ณ  ์ƒ๊ฐํ•˜๋‹ค๊ฐ€ ์งˆ๋ฌธํ•˜๊ธฐ์—์„œ ๋ฐ˜๋ก€๋ฅผ ๋ฐœ๊ฒฌํ–ˆ๋‹ค.

let input = require('fs').readFileSync('./dev/stdin').toString().trim().split("\n").map(v => v.replace("\r", ""));

let max = 0;
let location = ""
for (let i = 0; i < input.length; i++) {
  for (let j = 0; j < input[i].length; j++) {
    const num = input[i].split(" ")
    if (Number(num[j]) > max) {
      max = num[j]
      location = `${i + 1} ${j + 1}`
    };
  }
}
console.log(max);
console.log(location)

 

์ด ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ ์ „๋ถ€ 0 ์ด ๋“ค์–ด๊ฐ€์žˆ๋Š” ์˜ˆ์ œ ์ž…๋ ฅ์ธ ๊ฒฝ์šฐ location ์ด ์ถœ๋ ฅ๋˜์ง€ ์•Š๋Š”๋‹ค. 

location์— ์ดˆ๊ธฐ ๊ฐ’์œผ๋กœ "0 0" ์„ ์ฃผ๋˜์ง€

์•„๋‹ˆ๋ฉด ์ค‘๊ฐ„ if ์ ˆ์„ ์ดˆ๊ณผ => ์ด์ƒ์œผ๋กœ ์ˆ˜์ •ํ•ด์ฃผ๋ฉด ๋œ๋‹ค. 

 if (Number(num[j]) >= max) {

 

...ํ›„...! 

์ด˜์ด˜ํ•œ ์„ค๊ณ„, ์ดˆ๊ธฐ๊ฐ’์ด ์ค‘์š”ํ•˜๋‹ค๋Š” ๊ฑธ ๋ฐฐ์› ๋‹ค..!

728x90
๋ฐ˜์‘ํ˜•