본문 바로가기

BOJ

[백준] 10996번 별 찍기 -21 c++

#include <iostream>
using namespace std;

int main(void) {
	ios::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);
	int num;
	cin >> num;
	if (num == 1) {
		cout << "*";
		return 0;
	}
	for (int i = 1; i < 2 * num+1; i++) {
		if (i % 2 != 0) {
			for (int j = 1; j < num + 1; j++) {
				if (j % 2 != 0) cout << "*";
				else cout << " ";
			}
		}
		else {
			for (int j = 1; j < num + 1; j++) {
				if (j % 2 != 0) cout << " ";
				else cout << "*";
			}
		}	
		cout << "\n";
	}
	return 0;
}

'BOJ' 카테고리의 다른 글

[백준] 1157번 단어공부 c++  (0) 2020.04.26
[백준] 8958번 OX퀴즈 c++  (0) 2020.04.26
[백준] 1110번 더하기 사이클 c++  (0) 2020.04.26
[백준] 5543번 상근날드 c++  (0) 2020.04.26
[백준] 2884번 알람 시계 c++  (0) 2020.04.26