#include<vector>
#include<iostream>
#include<string>
using namespace std;
vector<int> ves;
int M, N;
char **map;
int times = 0;
void find(int x, int y, int index, int length, string& X, int dir)
{
if (map[x][y] != X[index - 1])
return;
if (index == length)
{
times++;
return;
}
if (dir == 1)
{
find(x, y + 1, index + 1, length, X, 1);
}
else if (dir == 2)
{
find(x + 1, y, index + 1, length, X, 2);
}
else
{
find(x + 1, y + 1, index + 1, length, X, 3);
}
}
int main()
{
int T;
cin >> T;
while (T--)
{
cin >> M >> N;
cin.ignore();
map = new char*[M + 2];
for (int i = 0; i < M + 2; i++)
{
map[i] = new char[N + 2];
for (int j = 0; j < N + 2; j++)
map[i][j] = ' ';
}
for (int i = 1; i <= M; i++)
{
string ss;
getline(cin, ss);
//cout << ss << endl;
if (ss.length() >= N)
{
for (int j = 1; j <= N; j++)
map[i][j] = ss[j - 1];
}
else
cout << ss.length() << " Error" << endl;
}
string X;
getline(cin, X);
int size = X.length();
times = 0;
for (int i = 1; i <= M; i++)
for (int j = 1; j <= N; j++)
{
if (map[i][j] == X[0])
{
find(i, j + 1, 2, size, X, 1);
find(i + 1, j, 2, size, X, 2);
find(i + 1, j + 1, 2, size, X, 3);
}
}
cout << times << endl;
times = 0;
for (int i = 0; i < M + 2; i++)
{
delete[] map[i];
}
delete[] map;
map = nullptr;
}
//cin.get();
return 0;
}
== 注意 == cin >>使用后 ,末尾的换行符并未清除,导致getline(cin, string)第一次读到的是换行,所以要加一个cin.ignore();