문제 : https://www.acmicpc.net/problem/10992


[ 알고리즘풀이 ]

쉬운 별 찍기 문제이므로 코드만 첨부하겠습니다.

#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 = 0; i < N; i++) {
		for (int j = 0; j < N - 1 - i; j++)
			cout << ' ';
		for (int j = 0; j < 2 * i + 1; j++)
			if (i == N - 1 || j == 0)
				cout << '*';
			else if (j == 2 * i)
				cout << '*';
			else
				cout << ' ';
		cout << '\n';
	}
}

 

+ Recent posts