알고리즘 문제
[백준] 10996번 별 찍기 - 21
feelcoding
2020. 3. 30. 17:34
728x90
https://www.acmicpc.net/problem/10996
10996번: 별 찍기 - 21
예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요.
www.acmicpc.net
#include <iostream>
using namespace std;
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
if (n == 1) {
cout << '*';
}
else {
for (int i = 0; i < 2 * n; i++) {
for (int j = 0; j < n; j++) {
if (i % 2 == 0) {
if (j % 2 == 0) {
cout << '*';
}
else {
cout << " ";
}
}
else {
if (j % 2 == 0) {
cout << " ";
}
else {
cout << '*';
}
}
}
cout << '\n';
}
}
return 0;
}
728x90