2for循环扫:1‘是炸弹判断其行和列的炸弹和减一是不是总炸弹数,是输出位置。
2’不是炸弹判断其行和列炸弹和是不是总炸弹数,是输出位置
#include<cstdio>
#include<cstring>
int main()
{
char c[1010][1010];
int a[1010]={0},b[1010]={0};
int h,w;
scanf("%d %d",&h,&w);
getchar(); //下面输入字符,上面换行要用getchar();
int num=0;
for(int i=1;i<=h;i++)
{
for(int j=1;j<=w;j++)
{
scanf("%c",&c[i][j]);
if(c[i][j]=='*')
{
a[i]++; //记录行的炸弹数
b[j]++; //记录列的炸弹数
num++; //总的炸弹数
}
}
getchar(); //换行,用getchar();
}
int flag=0;
for(int i=1;i<=h;i++)
{
for(int j=1;j<=w;j++)
{
if(c[i][j]=='*')
{
if(a[i]+b[j]-1==num) //c是炸弹减去本身多加的一判断行列和是不是总的数目
{
printf("YES\n%d %d\n",i,j);
flag=1;
break;
}
}
else
{
if(a[i]+b[j]==num) //c不是炸弹,判断行列和是不是炸弹总数
{
printf("YES\n%d %d\n",i,j);
flag=1;
break;
}
}
}
if(flag) //注意此时的连续跳出
break;
}
if(!flag)
printf("NO\n");
return 0;
}