문제 설명
1. 별 찍기 문제이다. (풀이가 곧 설명)
풀이
1. i 번째 줄에는 N - i 개의 공백이 들어가고 i 개의 "* " 가 들어가면 된다.
코드
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
import java.util.*; | |
import java.io.*; | |
/** | |
* https://www.acmicpc.net/problem/10991 | |
* BOJ 백준온라인져지 10991 별 찍기 - 16 풀이 | |
*/ | |
public class Main { | |
private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | |
public static void main(String args[]) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
int N = Integer.parseInt(br.readLine()); | |
for (int i = 1; i <= N; i++) { | |
for (int j = N; j > i; j--) bw.write(" "); | |
for (int j = 1; j <= i; j++) bw.write("* "); | |
bw.write("\n"); | |
} | |
bw.flush(); | |
} | |
} |
문제
예제를 보고 별 찍는 규칙을 유추한 뒤에 별을 찍어 보세요.
입력
첫째 줄에 N (1<=N<=100)이 주어진다.
출력
첫째 줄부터 N번째 줄까지 차례대로 별을 출력한다.
예제 입력 1
1
예제 출력 1
*
예제 입력 2
2
예제 출력 2
* * *
예제 입력 3
3
예제 출력 3
* * * * * *
예제 입력 4
4
예제 출력 4
* * * * * * * * * *
'IT > 알고리즘' 카테고리의 다른 글
BOJ 백준온라인져지 11653 소인수분해 풀이 (0) | 2018.06.27 |
---|---|
BOJ 백준온라인져지 10430 나머지 풀이 (0) | 2018.06.27 |
BOJ 백준온라인져지 2644 촌수계산 풀이 (0) | 2018.06.25 |
BOJ 백준온라인져지 1292 쉽게 푸는 문제 풀이 (0) | 2018.06.22 |
BOJ 백준온라인져지 5565 영수증 풀이 (0) | 2018.06.22 |