본문 바로가기
Algorithm

[백준] 2446번: 별 찍기 - 9

by 주발2 2020. 1. 16.
반응형

https://www.acmicpc.net/problem/2446

 

2446번: 별 찍기 - 9

첫째 줄부터 2×N-1번째 줄까지 차례대로 별을 출력한다.

www.acmicpc.net

코드

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int col = 0;
		
		// 위쪽 행(N-1개)
		for(int i=0; i<N-1; i++) {
			for(int j=0; j<i; j++)
				System.out.print(" ");
			for(int j=i*2; j<(N*2)-1; j++)
				System.out.print("*");
			System.out.println();
		}
		
		// 아래쪽 행(N개)
		for(int i=N-1; i<(N*2)-1; i++) {
			for(int j=col; j<N-1; j++)
				System.out.print(" ");
			for(int j=0; j<(col*2)+1; j++)
				System.out.print("*");
			System.out.println();
			col ++;
		}
		
		scan.close();
	}

}
반응형

'Algorithm' 카테고리의 다른 글

[백준] 14697번: 방 배정하기  (0) 2020.01.17
[백준] 15953번: 상금 헌터  (0) 2020.01.17
[백준] 2445번: 별 찍기 - 8  (0) 2020.01.16
[백준] 10820번: 문자열 분석  (0) 2020.01.16
[백준] 5073번: 삼각형과 세 변  (0) 2020.01.16

댓글