Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Tags
more
Archives
Today
Total
관리 메뉴

자이의 프로그래밍

별 찍기 - 9 본문

Algorithm/Cases-Study

별 찍기 - 9

Xi_kor 2020. 5. 4. 13:49

문제

예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요.

입력

첫째 줄에 N(1 ≤ N ≤ 100)이 주어진다.

출력

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

예제 입력 1

5

예제 출력 1

*********

 *******

  *****

   ***

    *

   ***

  *****

 *******

*********

 

------------------------------------------------------------------------------------------------------------------------------

 

#include <iostream>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int a = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < a; j++) {
			cout <<" ";
		}
		for (int j = 0; j < 2 * (n - a) - 1; j++) {
			cout << "*";
		}
		a++;
		cout << endl;
	}
	a = 1;
	for (int i = 0; i < 2*n-1-n; i++) {
		for (int j = 0; j < n-a-1; j++) {
			cout << " ";
		}
		for (int j = 0; j < 2 * a+1; j++) {
			cout << "*";
		}
		a++;
		cout << endl;
	}


	return 0;
}

'Algorithm > Cases-Study' 카테고리의 다른 글

방 배정  (0) 2020.05.04
Strfry  (0) 2020.05.04
개수 세기  (0) 2020.05.04
알파벳 개수  (0) 2020.05.04
카드 역배치  (0) 2020.05.04