-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ2446.java
More file actions
39 lines (37 loc) · 1.21 KB
/
Q2446.java
File metadata and controls
39 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Date: 2018. 9. 10.
* Author: inhyuck | https://github.com/inhyuck
* Solution URL: https://github.com/skhucode/skhucode-inhyuck
* Title: 별찍기 - 9
* Problem: 예제를 보고 별찍는 규칙을 유추한 뒤에 별을 찍어 보세요.
* URL: https://www.acmicpc.net/problem/2446
*/
package io.inhyuck.io;
import java.util.Scanner;
import java.util.Stack;
public class Q2446 {
public static void main(String[] args) {
int n = new Scanner(System.in).nextInt();
Stack<String> stack = new Stack<>();
int starCount, spaceCount;
StringBuilder builder = new StringBuilder();
for (int i = 1; i <= n; i++) {
spaceCount = (i - 1) * 2;
starCount = (2 * n - 1) - spaceCount;
builder.setLength(0);
for (int j = 0; j < spaceCount / 2; j++) {
builder.append(" ");
}
for (int j = 0; j < starCount; j++) {
builder.append("*");
}
if (i != n) {
stack.add(builder.toString());
}
System.out.println(builder);
}
for (int i = 0; i < n - 1; i++) {
System.out.println(stack.pop());
}
}
}