๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

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

[์•Œ๊ณ ๋ฆฌ์ฆ˜ || ๋ฐฑ์ค€] node JS - 10798 ์„ธ๋กœ ์ฝ๊ธฐ

728x90

๊ธฐ์กด ํ•˜๋˜ ๋ฐฉ์‹๊ณผ ๋‹ค๋ฅด๊ฒŒ for ๋ฌธ์„ ๋Œ๋ ค์•ผํ•ด์„œ ์‚ด์ง ํ—ท๊ฐˆ๋ ธ์ง€๋งŒ

 

1. ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด์˜ length ๋Š” ๋™์ผํ•˜์ง€ ์•Š๋‹ค.

2. ๊ฐ€์žฅ ๊ธด ๋ฌธ์ž์—ด์˜ length ๋งŒํผ ๋ฐ˜๋ณต๋ฌธ์„ ๋Œ ๋˜, ๋ฌธ์ž๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ์—๋งŒ result string ์— ๋ถ™์ธ๋‹ค.

 

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

const loop = Math.max(...input.map(v => v.length));
let result = "";

for (let i = 0; i < loop; i++) {
  for (let j = 0; j < input.length; j++) {
    if (input[j][i]) { result += input[j][i] }
  }
}

console.log(result)

 

728x90
๋ฐ˜์‘ํ˜•