按照边长从小到大输出,不是个数,因为这个错了一遍。。。

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

int main()
{
int squar[20][20];
int n, m, flag = 0;
while( scanf("%d %d",&n, &m) == 2 ){getchar();
memset(squar,0,sizeof(squar));
while(m--){
char c;
int x, y;
scanf("%c%d%d",&c, &x, &y);getchar();
if(c == 'H' && squar[x][y] == 0) squar[x][y] = 1;
else if(c == 'V' && squar[y][x] == 0) squar[y][x] = 2;
else if(c == 'H' && squar[x][y] == 2) squar[x][y] = 3;
else if(c == 'V' && squar[y][x] == 1) squar[y][x] = 3;
}
// for(i = 1; i <= n; i++){ for(j = 1; j <=n; j++) printf("%-3d",squar[i][j]);printf("\n");}
int num[15] = {0};
int i, j, k;
for(k = 1; k <= n-1; k++)
for(i = 1; i <= n-k; i++)
for(j = 1; j <= n-k; j++){
int x, y, on_off = 0;
for(x = i; x < i+k; x++){
if((squar[x][j] == 2 || squar[x][j] == 3) && (squar[x][j+k] == 2 || squar[x][j+k] == 3));
else break;
}
if(x >= i+k) on_off++;
for(y = j; y < j+k; y++){
if((squar[i][y] == 1 || squar[i][y] == 3) && (squar[i+k][y] == 1 || squar[i+k][y] == 3));
else break;
}
if(y >= j+k) on_off++;
if(on_off == 2) num[k]++;
}
if(flag!=0) printf("\n**********************************\n\n");
printf("Problem #%d\n\n",++flag);
int count = 0;
for(i = 1; i <= 10; i++)
if(num[i] != 0){
printf("%d square (s) of size %d\n", num[i], i);
count++;
}
if(count == 0) printf("No completed squares can be found.\n");
}
return 0;
}