#부호 + 테스트 케이스 번호 + " " + 5개이상 연속이 있으면 “YES”, 아니면 “NO” 출력
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++)
{
int N = sc.nextInt();
char[][] arr = new char[N][N];
String a;
String nun = "NO";
int countC = 0;
int countL = 0;
int countA = 0;
int countB = 0;
for(int i=0; i<N; i++) {
a = sc.next();
for(int j=0; j<N; j++) {
arr[i][j] = a.charAt(j);
}
}
for(int i=0; i<N; i++) {
countC=0;
countL=0;
for(int j=0; j<N; j++) {
if(arr[i][j]=='o') countC++;
if(arr[j][i]=='o') countL++;
if(i==j) {
if(arr[i][j]=='o') countA++;
}
if(i+j == N-1) {
if(arr[i][j]=='o') countB++;
}
}
if(countC==N || countL==N) nun="YES";
}
if(countA==N || countB==N) nun="YES";
System.out.println(nun);
}
}
}
else countC=0;해서 연속이 아닐 경우를 체크해줌i==j, i+j == N-1 하면 안됨import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++)
{
int N = sc.nextInt();
char[][] arr = new char[N][N];
String nun = "NO";
int countC = 0;
int countL = 0;
for(int i=0; i<N; i++) {
String a = sc.next();
for(int j=0; j<N; j++) {
arr[i][j] = a.charAt(j);
}
}
for(int i=0; i<N; i++) {
countC=0;
countL=0;
for(int j=0; j<N; j++) {
if(arr[i][j]=='o') countC++;
else countC=0;
if(arr[j][i]=='o') countL++;
else countL=0;
String b = nn(i,j,N,arr);
if(b.equals("YES")) nun="YES";
if(countC>=5 || countL>=5) nun="YES";
}
}
System.out.println("#" + test_case + " " + nun);
}
}
static String nn(int i, int j, int N, char[][] arr) {
int countA = 0;
int countB = 0;
if(i+4<=N-1 && j+5<N-1) {
for(int a=0; a<5; a++) {
if(arr[i+a][j+a] == 'o') countA++;
}
}
if(i+4<=N-1 && j>=4) {
for(int a=0; a<5; a++) {
if(arr[i+a][j-a] == 'o') countB++;
}
}
return countA==5 || countB==5 ? "YES" : "NO";
}
}
j+5<N-1 -> j+4<=N-1 수정import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++)
{
int N = sc.nextInt();
char[][] arr = new char[N][N];
String nun = "NO";
int countC = 0;
int countL = 0;
for(int i=0; i<N; i++) {
String a = sc.next();
for(int j=0; j<N; j++) {
arr[i][j] = a.charAt(j);
}
}
for(int i=0; i<N; i++) {
countC=0;
countL=0;
for(int j=0; j<N; j++) {
if(arr[i][j]=='o') countC++;
else countC=0;
if(arr[j][i]=='o') countL++;
else countL=0;
String b = nn(i,j,N,arr);
if(b.equals("YES")) nun="YES";
if(countC>=5 || countL>=5) nun="YES";
}
}
System.out.println("#" + test_case + " " + nun);
}
}
static String nn(int i, int j, int N, char[][] arr) {
int countA = 0;
int countB = 0;
if(i+4<=N-1 && j+4<=N-1) {
for(int a=0; a<5; a++) {
if(arr[i+a][j+a] == 'o') countA++;
}
}
if(i+4<=N-1 && j>=4) {
for(int a=0; a<5; a++) {
if(arr[i+a][j-a] == 'o') countB++;
}
}
return countA==5 || countB==5 ? "YES" : "NO";
}
}
