Coding_Test_C++
BaekJoon 2447번: 별 찍기 - 10
펄크럼
2021. 4. 8. 15:06
풀이법
1) N의 크기가 크지 않기에 재귀함수로 풀 수 있는 대표적인 문제이다.
2) 귀납적인 사고를 통해 문제를 해결하는 것이 Key point이다.
3) 종료 조건을 확실하게 정하는 것과, 좌표계를 이용하면 풀 수 있는 문제이다.
#include <iostream>
using namespace std;
int n;
void star(int i, int j, int N)
{
if (N == 1)
{
cout << "*";
return;
}
if (i % 3 == 1 && j % 3 == 1)
{
cout << " ";
return;
}
star(i / 3, j / 3, N / 3);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
star(i, j, n);
}
cout << "\n";
}
}
한계점 및 개선사항 (+주의사항)
좌표계를 이용하면 쉽게 풀 수 있는 문제인데 좌표계를 생각해 내는 것이 어려웠다.
빌 공간은 i%3==1 && j%3==1이다. 이를 잘게 쪼개는 재귀를 활용한다면 어렵지 않게 풀 수 있을 것이다.
github.com/pearlcrum/CodingTest/tree/main
pearlcrum/CodingTest
ForPracticingCodingTest. Contribute to pearlcrum/CodingTest development by creating an account on GitHub.
github.com