[SWEA D3] 15612. 체스판 위의 룩 배치 풀이- java

김민주·2022년 11월 17일
0

문제 - 15612. 체스판 위의 룩 배치

swexpertacademy 문제 바로가기 Click



설명

  1. 열,행 배열을 각각 만든다.
  2. O이 올 수 있는 자리에 O이 입력되면 행과 열을 표시한다.
  3. 이미 표시된 행과 열이라면 남은 줄만큼 입력을 넘기고 다음 테스트케이스로 넘어간다(Loop1)



자바 풀이


import java.util.*;
class Solution
{
	public static void main(String args[]) throws Exception
	{
		// 1행에 1개씩, 1열에 1개씩
		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{
                        //이미 정답이 될 수 없으니 continue
                            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++){ // false가 하나라도 있다면 no
                if(row[i] == false || col[i] == false) result = "no";
            }

			System.out.printf("#%d %s\n", test_case, result);
		}
	}
}
profile
𝐃𝐨𝐧'𝐭 𝐛𝐞 𝐚 𝐩𝐫𝐨𝐜𝐫𝐚𝐬𝐭𝐢𝐧𝐚𝐭𝐨𝐫💫

0개의 댓글