#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define SIZE 100
#define WIDTH 10

void initPaper(int (*whitePaper)[SIZE]);
void fillBlackPaper(int (*whitePaper)[SIZE], int x, int y);
int countBlackPaper(int (*whitePaper)[SIZE]);

int main()
{
    /* Declare Variables */
    int whitePaper[SIZE][SIZE];
    int numColorPaper;
    int xColorPaper;
    int yColorPaper;
    int i;
    int area;

    /* Initialize Variables */
    initPaper(whitePaper);

    /* Get Input */
    scanf("%d", &numColorPaper);

    /* Get Color Paper */
    for (i = numColorPaper; i > 0; i--)
    {
        scanf("%d", &xColorPaper);
        scanf("%d", &yColorPaper);
        xColorPaper--;
        yColorPaper--;
        fillBlackPaper(whitePaper, xColorPaper, yColorPaper);
    }
    area = countBlackPaper(whitePaper);
    printf("%d\n", area);
}

void initPaper(int (*whitePaper)[SIZE])
{
    /* Declare Variables */
    int row;
    int col;

    /* Fill White Paper */
    for (row = SIZE-1; row != -1; row--)
    {
        for (col = SIZE-1; col != -1; col--)
        {
            whitePaper[row][col] = 0;
        }
    }
}

void fillBlackPaper(int (*whitePaper)[SIZE], int x, int y)
{
    /* Declare Variables */
    int row;
    int col;

    /* Fille Black Paper */
    for (col = x; col < x + WIDTH; col++)
    {
        for(row = ((SIZE-1) - y); (row != ((SIZE - 1) - y - WIDTH )); row--)
        {
            if (
                (row < 0) |
                (row >= SIZE) | 
                (col < 0) |
                (col >= SIZE)
            )
            {
            break;
            }
            whitePaper[row][col] = 1;
        }
    }
}

int countBlackPaper(int (*whitePaper)[SIZE])
{
    /* Declare Variables */
    int cnt;
    int row;
    int col;

    /* Initialize Variables */
    cnt = 0;

    for (row = 0; row < SIZE; row++)
    {
        for (col = 0; col < SIZE; col++)
        {
            if (whitePaper[row][col] == 1)
            {
                cnt++;
            }
        }
    }
    return cnt;
}

'코딩테스트 > C' 카테고리의 다른 글

백준 11005 진법 변환 2  (2) 2024.07.14
백준 2745 진법 변환  (0) 2024.07.14
백준 10798 세로 읽기  (0) 2024.07.13
백준 2566 최댓값  (0) 2024.07.13
백준 2738 행렬덧셈  (0) 2024.07.13

+ Recent posts