[백준] 별 찍기 -7 2444

Soohyeon B·2022년 10월 17일
0

알고리즘 문제 풀이

목록 보기
17/70
#include <bits/stdc++.h>
using namespace std;


int main (void){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin >> n;
    int blank = (2*n-1)/2;
    
    for(int i=1; i<=n; i++, blank--){ //1 3 5 9 2n-1
        for(int j=0; j<blank; j++) cout << " ";
        for(int j=0; j<2*i-1; j++) cout << "*";
        cout << "\n";
    }
    
    for(int i=n-1; i>0; i--){
        for(int j=1; j<=n-i; j++) cout << " ";
        for(int j=1; j<=2*i-1; j++) cout <<"*";
        cout << "\n";
        
    }
    
}
profile
하루하루 성장하는 BE 개발자

0개의 댓글