终于有一个简单题了,没话说
#include<iostream>
#include<cstring>
using namespace std;
int H[10][10], V[10][10];
int ans[10];
int check(int i,int j,int n);
int check(int i, int j, int n)
{
for (int m = i; m < i + n; m++)
if (V[m][j] == 0 || V[m][j + n] == 0)return 0;
for (int m = j; m < j + n; m++)
if (H[i][m] == 0 || H[i + n][m] == 0)return 0;
return 1;
}
int main()
{
int a, b;
while (cin >> a >> b&&a)
{
memset(H, 0, sizeof(H));
memset(V, 0, sizeof(V));
memset(ans, 0, sizeof(ans));
while (b--)
{
char ch;
int i, j;
cin >> ch;
cin >> i >> j;
if (ch == 'H')H[i][j] = 1;
else V[i][j] = 1;
}
for (int i = 1; i < a; i++)
{
for (int j = 1; j < a; j++)
{
for (int c = 1; c <= a - i || c <= a - j; c++)
{
ans[c] += check(i, j, c);
}
}
}
for (int d = 1; d < a; d++)
if (ans[d])cout << ans[d] << " square(s) of size " << d << endl;
}
}