문제
10798번: 세로읽기
총 다섯줄의 입력이 주어진다. 각 줄에는 최소 1개, 최대 15개의 글자들이 빈칸 없이 연속으로 주어진다. 주어지는 글자는 영어 대문자 ‘A’부터 ‘Z’, 영어 소문자 ‘a’부터 ‘z’, 숫자 ‘0’
www.acmicpc.net
정답
const fs = require("fs");
const filePath = process.platform === "linux" ? "/dev/stdin" : "test.txt";
const input = fs
.readFileSync(filePath)
.toString()
.split("\n")
.map(_ => _.split(""));
// 배열에서 가장 긴 문자열의 길이 구하기
const maxStrNum = Math.max.apply(
null,
input.map(str => str.length)
);
let answer = [];
for (let j = 0; j < maxStrNum; j++) {
for (let i = 0; i < input.length; i++) {
// 배열의 해당 위치에 요소가 없는 경우 예외 처리
input[i] && input[i][j] && answer.push(input[i][j]);
}
}
console.log(answer.join(""));