inblog logo
|
LHS's Study Space
    알고리즘문제풀기C#

    [알고리즘 문제 풀기] 블라인드(2799)

    C#
    lhs's avatar
    lhs
    May 22, 2025
    [알고리즘 문제 풀기] 블라인드(2799)
    Contents
    1. 문제 풀이 아이디어2. 나의 정답 코드 3. 정리
    www.acmicpc.net
    https://www.acmicpc.net/problem/2799
    notion image

    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
    Contents
    1. 문제 풀이 아이디어2. 나의 정답 코드 3. 정리

    LHS's Study Space

    RSS·Powered by Inblog