(c#) 백준 2447 별찍기
2024. 2. 18. 01:31ㆍ문제 풀기
using System.Text;
int count = int.Parse(Console.ReadLine());
int powValue = 0;
for (int i = count; i != 1; i /= 3)
{
powValue++;
}
StringBuilder sb = new StringBuilder();
foreach (var i in GetStrings(powValue))
{
sb.AppendLine(i);
}
Console.WriteLine(sb.ToString());
string[] GetStrings(int value)
{
if (value == 1)
{
return new string[]
{
"***",
"* *",
"***",
};
}
var lowValue = GetStrings(value - 1);
int lowSize = lowValue.Length;
string emptyValue = string.Empty;
for (int i = 0; i < lowSize; i++)
{
emptyValue += " ";
}
string[] result = new string[lowSize * 3];
for (int y = 0; y < lowSize; y++)
{
result[y] += lowValue[y];
result[y] += lowValue[y];
result[y] += lowValue[y];
result[lowSize * 1 + y] += lowValue[y];
result[lowSize * 1 + y] += emptyValue;
result[lowSize * 1 + y] += lowValue[y];
result[lowSize * 2 + y] += lowValue[y];
result[lowSize * 2 + y] += lowValue[y];
result[lowSize * 2 + y] += lowValue[y];
}
return result;
}
재귀적으로 풀어봤습니다.
풀고나니 굉장히 간단한데 시간좀 걸렸네요.
'문제 풀기' 카테고리의 다른 글
(C#) 백준 14502번 : 연구소 (BFS) (0) | 2024.02.18 |
---|---|
(C#) 백준 9663번 N-Queen (퀸 배치 문제) (0) | 2024.02.18 |
(C#) 백준 7569 : 토마토 (BFS) (1) | 2024.02.18 |