๐ ์๊ณ ๋ฆฌ์ฆ/๋ฐฑ์ค JS
[๋ฐฑ์ค] JS/ 10798 ์ธ๋ก์ฝ๊ธฐ
Tamii
2021. 9. 29. 02:35
๋ฐ์ํ
๋ด ํ์ด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์ด๋ฉด '' , ์๋๋ฉด ๊ทธ ๊ฐ์ ๋ํด์ค
๐ฅณ ๋ ผ๋ฆฌ์ฐ์ฐ์์ ๊ฐ์ผ๋ก ์กฐ๊ฑด ์ฒ๋ฆฌ๋ฅผ ํ ์ ์๋ค๋.. ํ๋ก์ ํธํ ๋ ์์ฃผ ์ฌ์ฉํ๋๋ฐ ์๊ณ ๋ฆฌ์ฆ ํ ๋๋ ์ ์๊ฐ์ด ์๋๋์ง~