-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
입력값 => N | ||
출력값 => 2 x N - 1 번째 줄까지 차례대로 별 출력 | ||
*/ | ||
|
||
const fs = require("fs"); | ||
|
||
function main() { | ||
let input = Number(fs.readFileSync("/dev/stdin").toString().trim()); | ||
|
||
// 1부터 input줄까지 1개씩 늘려가면서 찍기 | ||
for (let i = 1; i <= input; i++) { | ||
// 앞에 별 출력 | ||
for (let j = 0; j < i; j++) { | ||
process.stdout.write("*"); | ||
} | ||
|
||
// 공백 출력 (한 줄에 N * 2 칸 수로 맞추기) | ||
for (let j = 0; j < input * 2 - 2 * i; j++) { | ||
process.stdout.write(" "); | ||
} | ||
|
||
// 뒤에 별 출력 | ||
for (let j = 0; j < i; j++) { | ||
process.stdout.write("*"); | ||
} | ||
|
||
// 줄바꿈 출력 | ||
process.stdout.write("\n"); | ||
} | ||
|
||
// input줄 이후부터는 1까지 1개씩 줄여가면서 찍기 | ||
for (let i = input - 1; i >= 1; i--) { | ||
// 앞에 별 출력 | ||
for (let j = i; j >= 1; j--) { | ||
process.stdout.write("*"); | ||
} | ||
|
||
// 공백 출력 (한 줄에 N * 2 칸 수로 맞추기) | ||
for (let j = 0; j < input * 2 - 2 * i; j++) { | ||
process.stdout.write(" "); | ||
} | ||
|
||
// 뒤에 별 출력 | ||
for (let j = i; j >= 1; j--) { | ||
process.stdout.write("*"); | ||
} | ||
|
||
// 줄바꿈 출력 | ||
process.stdout.write("\n"); | ||
} | ||
} | ||
|
||
main(); |