백준 algorithm

백준 2523 - 별 찍기 - 13

cosmohoo 2020. 8. 24. 22:33
반응형

문제 설명 

  • 단순한 별 찍기 문제입니다. 
  • 입력받은 숫자만큼 별의 개수를 늘려 프린트를 한다
  • 입력받은 숫자까지 별의 갯수를 프린트한 경우 숫자를 줄여가며 별을 프린트합니다.
  • 간단한 문제이기 때문에 코드를 보시면 이해가 됩니다. 

 

 

 

 

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int N;
    cin >> N;
    int cnt=1;
    
   while(cnt <= N)
   {
       for(int i=0; i<cnt; i++)
       {
           cout <<'*';
       }
       cout <<'\n';
       cnt++;
   }
    
    cnt = N-1;
    while(cnt >= 1)
    {
        for(int i=0; i<cnt; i++)
        {
            cout<<'*';
        }
        cout<<'\n';
        cnt--;
    }
    
    return 0;
}

 

 

반응형