티스토리 뷰

Algorithm/BOJ

백준 2448번 C++

poopooreum 2023. 8. 7. 16:36
반응형
백준 2448번 별 찍기-11

https://www.acmicpc.net/problem/2448

2448번: 별 찍기 - 11

첫째 줄에 N이 주어진다. N은 항상 3×2k 수이다. (3, 6, 12, 24, 48, ...) (0 ≤ k ≤ 10, k는 정수)

www.acmicpc.net



정답 코드

#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <queue>
#include <functional>

using namespace std;
char map[3073][6145];
void star(int n, int dx, int dy){
	if(n==3){
		map[dy][dx] = '*';
		map[dy+1][dx] = ' ';
		map[dy+1][dx-1] = '*';
		map[dy+1][dx+1] = '*';
		map[dy+2][dx-2] = '*';
		map[dy+2][dx-1] = '*';
		map[dy+2][dx] = '*';
		map[dy+2][dx+1] = '*';
		map[dy+2][dx+2] = '*';
		return;
	}
	star(n/2,dx-n/2,dy+n/2);
	star(n/2,dx+n/2,dy+n/2);
	star(n/2,dx,dy);
}
int main(int argc, char* argv[]) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=2*n; j++){
			map[i][j]=' ';
		}
	}
	star(n,n,1);
	for(int i=1; i<=n; i++){
		for(int j=1; j<=2*n; j++){
			cout<<map[i][j];
		}
		cout<<"\n";
	}
}

반응형

'Algorithm > BOJ' 카테고리의 다른 글

백준 2475번 C++  (0) 2023.08.07
백준 2468번 C++  (0) 2023.08.07
[C/C++] 백준 2447번 - 별 찍기10  (0) 2023.08.07
백준 2444번 C++  (0) 2023.08.06
백준 2443번 C++  (0) 2023.08.06
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함