3495 - 아스키 도형

2025. 3. 4. 16:31PS/백준

문제

https://www.acmicpc.net/problem/3495

느낀점

구현 기본 문제, 엣지 케이스를 잘 생각하자

풀이

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> board(h);
    for (int i = 0; i < h; i++)
    {
        cin >> board[i];
    }
    bool isStarted;
    int shapeCnt;
    int answer = 0;
    for (int i = 0; i < h; i++)
    {
        isStarted = false;
        shapeCnt = 0;
        for (int j = 0; j < w; j++)
        {
            if (board[i][j] == '.' && !isStarted)
            {
                continue;
            }
            else if (board[i][j] == '.' && isStarted)
            {
                answer += 2;
            }
            else
            {
                answer++;
                shapeCnt++;
                if (shapeCnt == 1)
                {
                    isStarted = true;
                }
                else
                {
                    isStarted = false;
                    shapeCnt = 0;
                }
            }
        }
    }
    cout << answer / 2;

    return 0;
}

'PS > 백준' 카테고리의 다른 글

16918 - 봄버맨  (0) 2025.03.06
9081 - 단어 맞추기  (0) 2025.03.05
2615 - 오목  (0) 2025.03.04
2564 - 경비원  (0) 2025.03.04
2002 - 추월  (0) 2025.02.28