๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ”‘ ์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฐฑ์ค€ JS

[๋ฐฑ์ค€] JS/ 10798 ์„ธ๋กœ์ฝ๊ธฐ

by Tamii 2021. 9. 29.
๋ฐ˜์‘ํ˜•

๋‚ด ํ’€์ด1(์˜ค๋‹ต)

const fs = require('fs');

let input = (fs.readFileSync('./dev/stdin') + '').split('\n');

let ans = '';
const wordArr = input.map((i) => i.split(''));
const turnCnt = wordArr.length;

let allCnt = 0;
while (allCnt < turnCnt) {
  wordArr.forEach((word) => {
    if (word[0] !== undefined) ans += word.shift();
    else allCnt += 1;
  });
}

console.log(ans);

 

 

1. ๊ธ€์ž๋ฅผ ์œ„์™€ ๊ฐ™์€ ์ด์ค‘๋ฐฐ์—ด๋กœ ์ƒ์„ฑ

2. ์ด ๋ฐฐ์—ด์˜ ๊ธธ์ด => ๊ฐœ์ˆ˜๋กœ ๋‘๊ณ 

3. ๋ฐ˜๋ณต๋ฌธ์„ ๋Œ๋ฉฐ ๊ฐ ์ค„ ๋ฐฐ์—ด์˜ ์ฒซ๋ฒˆ์งธ ๊ฐ’์ด ์—†์„๋•Œ๊นŒ์ง€ shift๋กœ ๋ถ™์—ฌ์คŒ'

 

 

 

๋‚ดํ’€์ด 2(๋Ÿฐํƒ€์ž„์—๋Ÿฌ)

const fs = require('fs');

let input = (fs.readFileSync('./dev/stdin') + '').split('\n');

let turnCnt = (fs.readFileSync('./test') + '')
  .replace(/ /gi, '')
  .replace('\n', '').length;

let ans = '';
const wordArr = input.map((i) => i.split(''));

let allCnt = 0;
while (allCnt < turnCnt) {
  wordArr.forEach((word) => {
    if (word[0] === ' ') word.shift();
    else if (word[0] !== undefined) ans += word.shift();
    else allCnt += 1;
  });
}

console.log(ans);

ใ…Žใ…Ž ์ƒˆ๋ฒฝ์— ์•ฝ๊ฐ„ ๋ง‰๊ธฐ ์‹์œผ๋กœ ํ‘ผ ํ’€์ด...

๋Ÿฐํƒ€์ž„์—๋Ÿฌ๊ฐ€

๋‚ ๋งŒ ํ–ˆ๋‹ค.


๋‹ค๋ฅธ ํ’€์ด*(์ •๋‹ต)

const fs = require('fs');

let input = (fs.readFileSync('./test') + '').toString().trim().split('\n');

const turnCnt = Math.max(...input.map((i) => i.length));

let ans = '';

for (let i = 0; i < turnCnt; i++) {
  for (let j = 0; j < input.length; j++) {
    ans += input[j][i] || '';
  }
}

console.log(ans);

1. ๋Œ์•„์•ผ ๋˜๋Š” cnt ๊ตฌํ•˜๊ธฐ 

2. ์ด์ค‘๋ฐฐ์—ด์„ ๋Œ๋ฉฐ ํ•ด๋‹น ๊ฐ’์ด undefined์ด๋ฉด '' , ์•„๋‹ˆ๋ฉด ๊ทธ ๊ฐ’์„ ๋”ํ•ด์คŒ

 

 

 

 

๐Ÿฅณ ๋…ผ๋ฆฌ์—ฐ์‚ฐ์ž์˜ ๊ฐ’์œผ๋กœ ์กฐ๊ฑด ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋‹ค๋‹ˆ.. ํ”„๋กœ์ ํŠธํ• ๋•Œ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ• ๋•Œ๋Š” ์™œ ์ƒ๊ฐ์ด ์•ˆ๋‚˜๋Š”์ง€~

๋Œ“๊ธ€