250x250
Notice
Recent Posts
Recent Comments
Link
\(@^0^@)/
[JS] ๋ฐฑ์ค 2439๋ฒ ๋ณ ์ฐ๊ธฐ - 2 ๋ณธ๋ฌธ
728x90
๐ฑ๐ 1. ๋ฌธ์ : 2439
https://www.acmicpc.net/problem/2439
๐ฅ 2.1 for๋ฌธ์ ์ค์ฒฉ์ผ๋ก ์ฌ์ฉํ ์ฝ๋
const fs = require('fs');
const file = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let input = fs.readFileSync(file).toString().split('\n');
let result = '';
let blank = '';
for (let i = 1; i <= input[0]; i++){
result += "*";
for (let j = 0; j < input[0]-i; j++){
blank += ' ';
}
console.log(blank + result);
blank = '';
}
๐ฅ 2.2 join ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ์ฝ๋
const fs = require('fs');
const file = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let input = fs.readFileSync(file).toString();
let num = Number(input);
// new Array(num) ๋ฐฐ์ด์ ์์ฑํด์ fill ๋ฉ์๋๋ก ๊ณต๋ฐฑ์ ์ฑ์ด๋ค.
// [ ' ', ' ', ' ', ' ', ' ' ]
let star = new Array(num).fill(' ');
// ์ธ๋ฑ์ค์ ๋ง์ง๋ง ๊ฐ(์ฌ๊ธฐ์ ์ธ๋ฑ์ค4)๋ถํฐ ์์๋๋ก star ๋ฐฐ์ด์ ๋ฃ๋๋ค.
for (let i = num - 1; i >= 0; i--){
star[i] = "*";
console.log(star.join(''));
}
๐ฅ 2.3 repeat ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ์ฝ๋
const fs = require('fs');
const file = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let input = fs.readFileSync(file).toString().split('\n');
for (let i = 1; i <= input[0]; i++){
console.log(" ".repeat(input[0] - i) + "*".repeat(i));
}
โก ํ์คํ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ์๊ฐ๋ ๋จ์ถ๋๊ณ , ๋ฉ๋ชจ๋ฆฌ๋ ์ค์ด๋ ๋ค
๋๋ ๋น ๋ฅธ ์์ผ ๋ด์ ์๊ณ ๋ฆฌ์ฆ์ ํ ๋, ๋ฉ์๋๋ค์ ์ ์ฌ์ ์์ ๋ฃ๊ณ ์ถ๋ค~~
โป ์ฐธ๊ณ : https://gurtn.tistory.com/33
โป ์ฐธ๊ณ : https://ryulurala.tistory.com/249
728x90
'์๊ณ ๋ฆฌ์ฆ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] ๋ฐฑ์ค 1110๋ฒ ๋ํ๊ธฐ ์ฌ์ดํด (0) | 2021.09.24 |
---|---|
[JS] ๋ฐฑ์ค 10952๋ฒ A+B - 5 (0) | 2021.09.24 |
[JS] ๋ฐฑ์ค 15552๋ฒ ๋น ๋ฅธ A+B (0) | 2021.09.17 |
[JS] ๋ฐฑ์ค 2884๋ฒ ์๋ ์๊ณ (0) | 2021.09.16 |
[JS] ๋ฐฑ์ค ๋ฐํ์ ์๋ฌ (readLine๋ชจ๋๋ก ์ ๋ ฅ ๋ฐ๋ ๋ฒ) (0) | 2021.09.16 |