
1. 문제 풀이 아이디어
- 블라인드마다 세로로 있는 4칸의 '*' 개수를 세어 종류(0~4)를 분류하여 문제를 해결할 수 있다.
2. 나의 정답 코드
using (StreamReader sr = new StreamReader(Console.OpenStandardInput()))
using (StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()))
{
int[] input = Array.ConvertAll(sr.ReadLine().Split(), int.Parse);
int m = input[0];
int n = input[1];
int[] result = new int[5];
string[] lines = new string[m * 5 + 1];
for (int i = 0; i < m * 5 + 1; i++)
{
lines[i] = sr.ReadLine();
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
int count = 0;
for (int k = 0; k < 4; k++)
{
if (lines[i * 5 + 1 + k][j * 5 + 1] == '*') count++;
}
result[count]++;
}
}
sw.WriteLine(String.Join(" ", result));
}
3. 정리
lines
배열에 전체 입력을 한 줄씩 저장한다. 총m * 5 + 1
줄을 입력받는다.
- 각 블라인드의 첫 열 기준으로 세로로 4칸을 확인하면서
'*'
개수를 센다.
- 해당 블라인드의
'*'
개수를 기준으로result
배열의 해당 인덱스를 증가시킨다.
- 모든 블라인드를 순회한 후, 결과를 출력하여 문제를 해결한다.
Share article