별 찍기 - 1 ~ 별 찍기 - 17
난이도: Bronze 3
프로그래밍 언어: Java
별 찍기 - 21
난이도: Bronze 2
프로그래밍 언어: Java
푼일자: 2021년 5월
별 찍기 - 1 : https://www.acmicpc.net/problem/2438
별 찍기 - 3 : https://www.acmicpc.net/problem/2440
별 찍기 - 5 : https://www.acmicpc.net/problem/2442
별 찍기 - 7 : https://www.acmicpc.net/problem/2444
별 찍기 - 9 : https://www.acmicpc.net/problem/2446
별 찍기 - 13 : https://www.acmicpc.net/problem/2523
별 찍기 - 15 : https://www.acmicpc.net/problem/10990
별 찍기 - 17 : https://www.acmicpc.net/problem/10990
별 찍기 - 21 : https://www.acmicpc.net/problem/10996
[2438번] 별 찍기 - 1
1
2
3
4
5
6
7
8
9
10
11
12
|
public class question_2438 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for (int i = 0; i < a; i++) {
StringBuilder sb = new StringBuilder();
for (int t = 0; t <= i; t++) sb.append("*");
System.out.println(sb);
}
}
}
|
cs |
[2440번] 별 찍기 - 3
1
2
3
4
5
6
7
8
9
10
11
12
|
public class question_2440 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for (int i = a; i > 0; i--) {
StringBuilder sb = new StringBuilder();
for (int t = i; t > 0; t--) sb.append("*");
System.out.println(sb);
}
}
}
|
cs |
[2442번] 별 찍기 - 5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
public class question_2442 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for (int i = 0; i < a; i++) {
System.out.printf(getStackString(a - i - 1, " "));
System.out.println(getStackString(i * 2 + 1, "*"));
}
}
public static String getStackString(int count, String str) {
StringBuilder sb = new StringBuilder();
while(count-- > 0) sb.append(str);
return sb.toString();
}
}
|
cs |
[2444번] 별 찍기 - 7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
public class question_2444 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
Stack<String> stack = new Stack<>();
for (int i = 0; i < a; i++) {
stack.add(getStackString(a - i - 1, " ") + getStackString(i * 2 + 1, "*"));
System.out.println(stack.peek());
}
while(stack.size() != 1) {
stack.pop();
System.out.println(stack.peek());
}
}
public static String getStackString(int count, String str) {
StringBuilder sb = new StringBuilder();
while(count-- > 0) sb.append(str);
return sb.toString();
}
}
|
cs |
[2446번] 별 찍기 - 9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
public class question_2446 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
Stack<String> stack = new Stack<>();
for (int i = 0; i < a; i++) {
stack.add(getStackString(i, " ") + getStackString((a - i) * 2 -1, "*"));
System.out.println(stack.peek());
}
while(stack.size() != 1) {
stack.pop();
System.out.println(stack.peek());
}
}
public static String getStackString(int count, String str) {
StringBuilder sb = new StringBuilder();
while(count-- > 0) sb.append(str);
return sb.toString();
}
}
|
cs |
[2523번] 별 찍기 - 13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
public class question_2523 { // 별 찍기 - 13
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
Stack<String> stack = new Stack<>();
for (int i = 0; i < a; i++) {
StringBuilder sb = new StringBuilder();
for (int t = 0; t <= i; t++) sb.append("*");
stack.add(sb.toString());
System.out.println(stack.peek());
}
while(stack.size() != 1) {
stack.pop();
System.out.println(stack.peek());
}
}
}
|
cs |
[10990번] 별 찍기 - 15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
public class question_10990 { // 별 찍기 - 15
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for (int i = 0; i < a; i++) {
System.out.printf(getStackSpace(a - i - 1));
if (i == 0) System.out.println("*");
else System.out.println("*" + getStackSpace(i * 2 - 1) + "*");
}
}
public static String getStackSpace(int count) {
StringBuilder sb = new StringBuilder();
while(count-- > 0) sb.append(" ");
return sb.toString();
}
}
|
cs |
[10992번] 별 찍기 - 17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
public class question_10992 { // 별 찍기 - 17
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for (int i = 0; i < a; i++) {
System.out.printf(getStackSpace(a - i - 1, " "));
if (i == 0) System.out.println("*");
else if (i == a - 1) System.out.println(getStackSpace(i * 2 + 1, "*"));
else System.out.println("*" + getStackSpace(i * 2 - 1, " ") + "*");
}
}
public static String getStackSpace(int count, String str) {
StringBuilder sb = new StringBuilder();
while(count-- > 0) sb.append(str);
return sb.toString();
}
}
|
cs |
[10996번] 별 찍기 - 21
1
2
3
4
5
6
7
8
9
10
11
12
13
|
public class question_10996 { // 별 찍기 - 21
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for (int i = 0; i < a * 2; i++) {
for (int t = 0; t < a; t++)
if ((i + t) % 2 == 0) System.out.printf("*");
else System.out.printf(" ");
System.out.printf("\n");
}
}
}
|
cs |
끝 !
반응형