背景:1Y!!!调试一个小时。没有仔细看题,V 2 1,实际上表示的是第二列第一行,因为这个调试了好久。要逐渐养成耐心读代码的习惯!
思路:把行和列的分别记录在两个数组你,让后从边长为1开始枚举出所有即可!
学习:1.scanf读取字符的时候一定要考虑到,换行行符在键盘缓冲区的遗留问题!
#include<stdio.h>
#include<string.h>
int main(void){
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int count=1,t,h,v,side;
while(~scanf("%d",&side)){
side--;
if(count-1) printf("\n**********************************\n\n");
printf("Problem #%d\n\n",count++);
int horizontal[11][11],vertical[11][11];
scanf("%d%*c",&t);
memset(horizontal,0,sizeof(horizontal));
memset(vertical,0,sizeof(vertical));
while(t--){
char direction;
scanf("%c%d%d%*c",&direction,&h,&v);
if(direction == 'H') horizontal[h][v]=1;
else vertical[v][h]=1;
}
bool have=true;
for(int i=1;i <= side;i++){
int ans=0;
for(int j=1;j <= side+1-i;j++){
for(int k=1;k <=side+1-i;k++){
bool ok=true;
for(int ii=0;ii < i;ii++){
if(!horizontal[j][k+ii]) ok=false;
if(!horizontal[j+i][k+ii]) ok=false;
if(!vertical[j+ii][k]) ok=false;
if(!vertical[j+ii][k+i]) ok=false;
}
if(ok) ans++;
}
}
if (ans){
printf("%d square (s) of size %d\n",ans,i);
have=false;
}
}
if(have) printf("No completed squares can be found.\n");
}
return 0;
}