///@author Sycamore, ZJNU
///@date 2017-02-07
#include<iostream>
using namespace std;
char mat[250][250];
int main()
{
int T,M,N;
cin >> T;
while (T--)
{
cin >> M >> N;
int c = 0;
for (int i = 0; i < M; i++)
for (int j = 0; j < N; j++)
cin >> mat[i][j];
if(M-1&&N-1)
{
for(int top=0;top<M-1;top++)
for(int left=0;left<N-1;left++)
for (int bottom = top+1; bottom < M; bottom++)
{
if (mat[top][left] == mat[bottom][left])
{
for (int right = left+1; right < N; right++)
{
if (mat[top][left] == mat[top][right] && mat[bottom][left] == mat[bottom][right])
c++;
}
}
}
}
cout << c << endl;
}
return 0;
}
原文:http://www.cnblogs.com/zjnu/p/7257963.html