-
[2445] 별 찍기 - 8BOJ 2022. 2. 22. 20:28
https://www.acmicpc.net/problem/2445
2445번: 별 찍기 - 8
첫째 줄부터 2×N-1번째 줄까지 차례대로 별을 출력한다.
www.acmicpc.net
가장 왼쪽편에 있는 *만 보면, n개의 줄에 1..n개의 *을 찍는 규칙에, 좌우대칭/상하대칭을 이용했음을 알 수 있다.
#include <bits/stdc++.h>using namespace std;#ifdef ONLINE_JUDGEconstexpr bool local = false;#elseconstexpr bool local = true;#endifusing ll = long long;using pi = pair<ll, ll>;vector<string> ans;int main(void) {if (!local) ios_base::sync_with_stdio(0), cin.tie(0);int i, j, n;cin >> n;for (i = 0; i < n - 1; i++) {string cur = string(i + 1, '*') + string(2 * n - (2 * i + 2), ' ') +string(i + 1, '*');ans.push_back(cur);cout << cur << '\n';}cout << string(2 * n, '*') << '\n';for (auto it = ans.rbegin(); it != ans.rend(); it++) cout << *it << '\n';return 0;}
'BOJ' 카테고리의 다른 글
[3991] 한번 쏘면 멈출 수 없어 (0) 2022.02.23 [21554] 마법의 돌 장난감 (0) 2022.02.22 [20291] 파일 정리 (0) 2022.02.22 [10728] XOR삼형제 1 (0) 2022.02.21 [4991] 로봇 청소기 (0) 2022.02.21