[BAEKJOON 2442번 : 별 찍기 - 5]
[문제]

[Solution]
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n - i; ++j) {
cout << " ";
}
for (int j = 1; j <= 2 * i - 1; ++j) {
cout << "*";
}
cout << endl;
}
}
[BAEKJOON 2443번 : 별 찍기 - 6]
[문제]

[Solution]
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = n; i >= 1; --i)
{
for (int j = 0; j < n - i; ++j)
{
cout << " ";
}
for (int j = 0; j < 2 * i - 1; ++j)
{
cout << "*";
}
cout << endl;
}
return 0;
}
[BAEKJOON 2444번 : 별 찍기 - 7]
[문제]

[Solution]
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n - i; ++j) {
cout << " ";
}
for (int j = 1; j <= 2 * i - 1; ++j) {
cout << "*";
}
cout << endl;
}
for (int i = n - 1; i >= 1; --i)
{
for (int j = 0; j < n - i; ++j)
{
cout << " ";
}
for (int j = 0; j < 2 * i - 1; ++j)
{
cout << "*";
}
cout << endl;
}
return 0;
}
[BAEKJOON 2445번 : 별 찍기 - 8]
[문제]

[Solution]
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= i ; ++j)
{
cout << "*";
}
for (int j = 1; j <= 2 * (n - i); ++j)
{
cout << " ";
}
for (int j = 1; j <= i; ++j)
{
cout << "*";
}
cout << "\n";
}
for (int i = n - 1; i >= 1; --i)
{
for (int j = 1; j <= i; ++j)
{
cout << "*";
}
for (int j = 1; j <= 2 * (n - i); ++j)
{
cout << " ";
}
for (int j = 1; j <= i; ++j)
{
cout << "*";
}
cout << "\n";
}
return 0;
}
[BAEKJOON 2446번 : 별 찍기 - 9]
[문제]

[Solution]
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = n; i >= 1; --i)
{
for (int j = 0; j < n - i; ++j)
{
cout << " ";
}
for (int j = 0; j < 2 * i - 1; ++j)
{
cout << "*";
}
cout << "\n";
}
for (int i = 2; i <= n; ++i)
{
for (int j = 0; j < n - i; ++j)
{
cout << " ";
}
for (int j = 0; j < 2 * i - 1; ++j)
{
cout << "*";
}
cout << "\n";
}
return 0;
}'코딩 테스트' 카테고리의 다른 글
| [코딩테스트 12일차] BAEKJOON 2935번 : 소음 (0) | 2025.05.03 |
|---|---|
| [코딩테스트 11일차] BAEKJOON 2525번 : 오븐시계, BAEKJOON 2914번 : 저작권 (0) | 2025.05.01 |
| [코딩테스트 9일차] BAEKJOON 10808번, 11365번, 11720번 (0) | 2025.04.22 |
| [코딩테스트 8일차] BAEKJOON 2439, 2440번 : 별 찍기 - 2, 3 (0) | 2025.04.20 |
| [코딩테스트 7일차] BAEKJOON 1264번 : 모음의 개수 (0) | 2025.04.19 |