문제 : https://www.acmicpc.net/problem/2522
[알고리즘풀이]
절반을 기준으로 위 / 아래로 나눠서 구현한다.
#include<iostream>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = n - i; j > 0; j--)
cout << ' ';
for (int j = 1; j <= i; j++)
cout << '*';
cout << '\n';
}
for (int i = 1; i < n; i++) {
for(int j = 0; j < i; j++)
cout << ' ';
for (int j = 0; j < n - i; j++)
cout << '*';
cout << '\n';
}
return 0;
}
'Problem Solving > BOJ' 카테고리의 다른 글
[BOJ] 10819 - 차이를 최대로 (0) | 2019.09.30 |
---|---|
[BOJ] 1520 - 내리막 길 (0) | 2019.09.29 |
[BOJ] 13458 - 시험 감독 (0) | 2019.09.29 |
[BOJ] 2446 - '별 찍기 - 9' (0) | 2019.09.29 |
[BOJ] 15781 - 헬멧과 조끼 (0) | 2019.09.29 |