您的位置:首页 > 其它

白色网格统计poj1656-Counting Black

2016-07-31 15:32 453 查看
题意是有一个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);
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息