题意是有一个100x100的网格,然后我们根据指示在网格中涂上白色或者黑色。
然后统计指定网格中白色格子的数量。
#include "stdio.h"
#include "string.h"
void main()
{
int color[105][105];
char s[10];
int n, i, j, x, y, l, sum;
while (scanf("%d", &n) != EOF)
{
memset(color, 0, sizeof(color));
while (n--)
{
scanf("%s %d %d %d", &s, &x, &y, &l);
if (strcmp(s, "BLACK") == 0)
{
for (i = x; i < x + l; i++)
for (j = y; j < y + l; j++)
color[i][j] = 1;
}
else if (strcmp(s, "WHITE") == 0)
{
for (i = x; i < x + l; i++)
for (j = y; j < y + l; j++)
color[i][j] = 0;
}
else
{
sum = 0;
for (i = x; i < x + l; i++)
for (j = y; j < y + l; j++)
if (color[i][j] == 1) sum++;
printf("%d\n", sum);
}
}
}
}