๋ฐ์ํ
๋ด ํ์ด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์ด๋ฉด '' , ์๋๋ฉด ๊ทธ ๊ฐ์ ๋ํด์ค
๐ฅณ ๋ ผ๋ฆฌ์ฐ์ฐ์์ ๊ฐ์ผ๋ก ์กฐ๊ฑด ์ฒ๋ฆฌ๋ฅผ ํ ์ ์๋ค๋.. ํ๋ก์ ํธํ ๋ ์์ฃผ ์ฌ์ฉํ๋๋ฐ ์๊ณ ๋ฆฌ์ฆ ํ ๋๋ ์ ์๊ฐ์ด ์๋๋์ง~
'๐ ์๊ณ ๋ฆฌ์ฆ > ๋ฐฑ์ค JS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] JS/ 10808 ์ํ๋ฒณ ๊ฐ์ (0) | 2021.09.30 |
---|---|
[๋ฐฑ์ค] JS/ 4949 ๊ท ํ์กํ ์ธ์ (0) | 2021.09.29 |
[๋ฐฑ์ค] JS/ 14561 ํ๋ฌธ (0) | 2021.09.27 |
[๋ฐฑ์ค] node.js ์ ๋ ฌ / 1181 ๋จ์ด์ ๋ ฌ (0) | 2021.05.02 |
[๋ฐฑ์ค] ๋ฌธ์์ด / node.js 1427 ์ํธ์ธ์ฌ์ด๋ (0) | 2021.05.01 |
๋๊ธ