#include<iostream>
#include<string>
using namespace std;
string n[115][115];
string t[101][101];
int geshu(int a,int b){
int g=0;
string c;
c=n[a][b]+n[a+1][b]+n[a+2][b]+n[a+3][b]+n[a+4][b]+n[a+5][b]+n[a+6][b];
if(c=="yizhong"||c=="gnohziy")
g++;
c=n[a][b]+n[a+1][b+1]+n[a+2][b+2]+n[b+3][b+3]+n[a+4][b+4]+n[a+5][b+5]+n[a+6][b+6];
if(c=="yizhong"||c=="gnohziy")
g++;
c=n[a][b]+n[a-1][b+1]+n[a-2][b+2]+n[a-3][b+3]+n[a-4][b+4]+n[a-5][b+5]+n[a-6][b+6];
if(c=="yizhong"||c=="gnohziy")
g++;
c=n[a][b]+n[a][b+1]+n[a][b+2]+n[a][b+3]+n[a][b+4]+n[a][b+5]+n[a][b+6];
if(c=="yizhong"||c=="gnohziy")
g++;
return g;
}
int main(){
int N,ji=0;
string k;
cin>>N;
for(int i=7;i<=N+7;i++){//输入处理
cin>>k;
for(int j=7;j<=N+7;j++){
n[i][j]=k.substr(j,1);
}
}
for(int i=7;i<=N+7;i++)
for(int j=7;j<=N+7;j++)
ji+=geshu(i,j);
cout<<ji;
}
自己用样例得到的结果:
7
aaaaaaa//输入
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr: __pos (which is 8) > this->size() (which is 7)
--------------------------------
Process exited after 8.192 seconds with return value 3
请按任意键继续. . .
什么意思?没看懂