문제 - 15612. 체스판 위의 룩 배치
swexpertacademy 문제 바로가기 Click
설명
- 열,행 배열을 각각 만든다.
- O이 올 수 있는 자리에 O이 입력되면 행과 열을 표시한다.
- 이미 표시된 행과 열이라면 남은 줄만큼 입력을 넘기고 다음 테스트케이스로 넘어간다(Loop1)
자바 풀이
import java.util.*;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
Loop1:
for(int test_case = 1; test_case <= T; test_case++)
{
boolean[] row = new boolean[8];
boolean[] col= new boolean[8];
Arrays.fill(row,false);
Arrays.fill(row,false);
Loop2:
for(int i=0;i<8;i++){
String s = sc.next();
int cnt = 0;
Loop3:
for(int j =0;j<8;j++){
if(s.charAt(j) == 'O'){
if(col[j] ==false && row[i]== false ){
col[j]= true;
row[i] = true;
}else{
System.out.printf("#%d no\n", test_case);
for(int k =i+1;k<8;k++ ) sc.next();
continue Loop1;
}
}
}
}
String result = "yes";
for(int i=0;i<8;i++){
if(row[i] == false || col[i] == false) result = "no";
}
System.out.printf("#%d %s\n", test_case, result);
}
}
}