알고리즘 문제풀이/백준
[백준 2447] 별 찍기 10
홍시홍
2019. 12. 14. 11:50
https://www.acmicpc.net/problem/2447
2447번: 별 찍기 - 10
첫째 줄에 N이 주어진다. N은 항상 3의 제곱꼴인 수이다. (3, 9, 27, ...) (N=3k, 1 ≤ k < 8)
www.acmicpc.net
요구사항
주어진 패턴대로 '*', ' ' 출력
풀이
n=3 일때
***
* *
***
n=9 일때
*********
* ** ** *
*********
*** ***
* * * *
*** ***
*********
* ** ** *
*********
유추 해보면
조건 1
row%3 =1 , col %3=1 일때 ' '
조건 2
row/ (n/3) =1 , col / (n/3) =1 일때 ' '이다.
#include <iostream>
using namespace std;
char map[10000][10000];
int mynum;
void draw(int r, int c)
{
if (r % 3 == 1 && c % 3 == 1)
{
cout << " ";
return;
}
if (r / mynum == 1 && c / mynum == 1)
{
cout << " ";
return;
}
else
cout << "*";
}
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin >> n;
mynum = n / 3;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
draw(i, j);
}
cout << endl;
}
}