2445번 - 별 찍기 - 8
문제
예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요.
입력
첫째 줄에 N(1 ≤ N ≤ 100)이 주어진다.
출력
첫째 줄부터 2×N-1번째 줄까지 차례대로 별을 출력한다.
문제 링크
https://www.acmicpc.net/problem/2445
난이도: 브론즈 3
알고리즘 분류
- 구현
C++를 사용한 풀이
#include <iostream>
using namespace std;
int main(void){
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=1;i<=n;++i){
for(int j=0;j<i;++j) cout<<"*";
for(int j=0;j<2*n - 2*i;j++) cout<<" ";
for(int j=0;j<i;++j) cout<<"*";
cout<<"\n";
}
for(int i=n-1;i>=1;--i){
for(int j=0;j<i;++j) cout<<"*";
for(int j=0;j<2*n - 2*i;j++) cout<<" ";
for(int j=0;j<i;++j) cout<<"*";
cout<<"\n";
}
}
댓글남기기