附上代码:
java
import java.util.Scanner;
public class TargetPractice {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while(T>0){
char[][]arr = new char[10][10];
for(int i=0;i<10;i++){
arr[i] = scan.next().toCharArray();
}
var res = getScore(arr);
System.out.println(res);
T--;
}
}
public static int getScore(char[][] a){
int ans = 0;
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
if(a[i][j]=='X'){
if(i==0||j==0||i==9||j==9)ans+=1;
else if(i==1||j==1||i==8||j==8)ans+=2;
else if(i==2||j==2||i==7||j==7)ans+=3;
else if(i==3||j==3||i==6||j==6)ans+=4;
else ans+=5;
}
}
}
return ans;
}
}
看了一下大佬的题解,确实没想到还能这样写: