Source Code
Problem: 1440 User: 0000000000
Memory: 1196K Time: 0MS
Language: GCC Result: Accepted
Source Code
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
while (n--)
{
int wide;
scanf("%d", &wide);
char chess[16][16]={'\0'};
for (int i = 0; i < wide; i++)
{
scanf("%s", chess + i);
}
int bcount = 0, wcount = 0;
int Black = 0, Whire = 0;
for (int i = 0; i < wide; i++)
{
bcount = 0, wcount = 0;
for (int j = 0; j <= wide; j++)
{
if (chess[i][j] != 'W')
{
if (wcount >= 3)
{
Whire++;
}
wcount = 0;
}
else if (chess[i][j] == 'W')
{
wcount++;
}
if (chess[i][j] != 'B')
{
if (bcount >= 3)
{
Black++;
}
bcount = 0;
}
else if (chess[i][j] == 'B')
{
bcount++;
}
}
}
for (int i = 0; i < wide; i++)
{
bcount = 0, wcount = 0;
for (int j = 0; j <= wide; j++)
{
if (chess[j][i] != 'W')
{
if (wcount >= 3)
{
Whire++;
}
wcount = 0;
}
else if (chess[j][i] == 'W')
{
wcount++;
}
if (chess[j][i] != 'B')
{
if (bcount >= 3)
{
Black++;
}
bcount = 0;
}
else if (chess[j][i] == 'B')
{
bcount++;
}
}
}
for (int i = 2; i < wide; i++)
{
bcount = 0, wcount = 0;
int count = 1 + i;
for (int j = 0; j <= count; j++)
{
if (chess[i - j][j] != 'W')
{
if (wcount >= 3)
{
Whire++;
}
wcount = 0;
}
else if (chess[i - j][j] == 'W')
{
wcount++;
}
if (chess[i - j][j] != 'B')
{
if (bcount >= 3)
{
Black++;
}
bcount = 0;
}
else if (chess[i-j][j] == 'B')
{
bcount++;
}
}
}
for (int i = 1; i < wide - 2; i++)
{
bcount = 0, wcount = 0;
int count = wide - i;
for (int j = 0; j <= count; j++)
{
if (chess[j + i][(wide - 1) - j] != 'W')
{
if (wcount >= 3)
{
Whire++;
}
wcount = 0;
}
else if (chess[j + i][(wide - 1) - j] == 'W')
{
wcount++;
}
if (chess[j + i][(wide - 1) - j] != 'B')
{
if (bcount >= 3)
{
Black++;
}
bcount = 0;
}
else if (chess[j + i][(wide - 1) - j] == 'B')
{
bcount++;
}
}
}
for (int i = 0; i < wide - 2; i++)
{
bcount = 0, wcount = 0;
int count = wide - i;
for (int j = 0; j <= count; j++)
{
if (chess[j + i][j] != 'W')
{
if (wcount >= 3)
{
Whire++;
}
wcount = 0;
}
else if (chess[j + i][j] == 'W')
{
wcount++;
}
if (chess[j + i][j] != 'B')
{
if (bcount >= 3)
{
Black++;
}
bcount = 0;
}
else if (chess[j+i][j] == 'B')
{
bcount++;
}
}
}
for (int i = 2; i < wide - 1; i++)
{
bcount = 0, wcount = 0;
int count = 1 + i;
for (int j = 0; j <= count; j++)
{
if (chess[i - j][(wide - 1) - j] != 'W')
{
if (wcount >= 3)
{
Whire++;
}
wcount = 0;
}
else if (chess[i - j][(wide - 1) - j] == 'W')
{
wcount++;
}
if (chess[i - j][(wide - 1) - j] != 'B')
{
if (bcount >= 3)
{
Black++;
}
bcount = 0;
}
else if (chess[i - j][(wide - 1) - j] == 'B')
{
bcount++;
}
}
}
printf("%d %d\n", Black, Whire);
}
}
没什么技巧,就是一行行扫描