简单的搜索。详见代码。
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
int dx[]= {0,1,1,1,0,-1,-1,-1};
int dy[]= {1,1,0,-1,-1,-1,0,1};
using namespace std;
char S[10][10];
int SS (int a,int b) {
int xx,yy,sum=0;
for (int i=0; i<8; ++i) {//8个方向
xx=a+dx[i];
yy=b+dy[i];
int cnt=0;
while (S[xx][yy]=='L') {
cnt++;//one more,统计该方向数量
xx+=dx[i];
yy+=dy[i];
}
if (S[xx][yy]=='D') {sum+=cnt;}
}
return sum;
}
int main() {
int T; cin>>T;
for (int cas=0; cas<T; cas++) {
for (int i=0; i<8; ++i) {
scanf ("%s",S[i]);/*输入一直没处理好,所以直接用%s输入解决问题*/
}
int ans=0,t=0;
for (int i=0; i<8; ++i) {
for (int j=0; j<8; ++j) {
if (S[i][j]=='*')/*!*/ {
t= (SS (i,j) );
ans=max (ans,t);//find the largest one
}
}
}
printf ("Case %d: %d\n",cas+1,ans);
}
return 0;
}