这题你只要以 o 为点向 right, left, up, down 寻找 *,只要找到了四个,就是 ans++;最后输出。
AC 代码:
#include<bits/stdc++.h>
using namespace std;
bool b[60][60];
struct str{
int x;
int y;
}place[2600];
char c[60][60];
int m,n;
int cnt;
int cn;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>c[i][j];
if(c[i][j]=='o'){
cnt++;
place[cnt].x=i;
place[cnt].y=j;
}
}
}
for(int i=1;i<=cnt;i++){
bool right=false;
bool left=false;
bool up=false;
bool down=false;
for(int j=1;j<=place[i].y;j++){
if(c[place[i].x][j]=='*'){
left=true;
break;
}
}
for(int j=place[i].y;j<=m;j++){
if(c[place[i].x][j]=='*'){
right=true;
break;
}
}
for(int j=1;j<=place[i].x;j++){
if(c[j][place[i].y]=='*'){
up=true;
break;
}
}
for(int j=place[i].x;j<=n;j++){
if(c[j][place[i].y]=='*'){
down=true;
}
}
if(right&&left&&up&&down){
cn++;
}
}
cout<<cn;
return 0;
}本题解使用了 deepseek-v4-pro 进行润色以保证格式的正确。
作者保证自身贡献大于AI