Algorithm/BOJ
백준 2444번 C++
poopooreum
2023. 8. 6. 20:42
반응형
백준 2444번 별 찍기-7
https://www.acmicpc.net/problem/2444
2444번: 별 찍기 - 7
첫째 줄부터 2×N-1번째 줄까지 차례대로 별을 출력한다.
www.acmicpc.net


정답 코드
#include<iostream>
using namespace std;
char arr[101] = { 0, };
int n;
void abc(int a) {
arr[n + a] = '*';
arr[n - a] = '*';
for (int x = 1; x <= n + a; x++) {
if (arr[x] == '*')
cout << '*';
else
cout << " ";
}
cout << endl;
}
int main() {
cin >> n;
for (int x = 0; x < n; x++) {
abc(x);
}
for (int i = 1; i < n; i++)
{
for (int j = 0; j < i; j++) {
cout << ' ';
}
for (int b = i + 1; b < n * 2 - i; b++) {
cout << '*';
}
cout << endl;
}
return 0;
}
반응형