몇일 전에 삼성에서 주관하는 ssafy에 지원서를 넣었기에 ssafy에서 시행하는 sw전공자용 코딩테스트 대비를 위해 오늘부터 swea문제를 풀기 시작 하였다.
<문제 : 15612 체스판 위의 룩 배치>
이 문제의 경우 개발자 지망생이라면 다 아실 n-Queen의 하위버전 문제였다. n-Queen의 경우 대각선까지 생각하여 배치를 해야하지만 이 문제의 경우 대각선의 영향은 없었다.
for(int test_case = 1; test_case <= T; test_case++)
{
boolean correct = true;
int [] rookArr = new int[8];
for(int i = 0; i < 8; i++){
String rook = sc.next();
int Ocount = 0;
if(rook.equals("........")){
correct = false;
}
for(int j = 0; j < rook.length(); j++){
if(rook.charAt(j) == 'O'){
Ocount ++;
rookArr[i] = j;
}
if(Ocount > 1){
correct = false;
}
}
}
if(correct){
boolean lastCorrect = true;
for(int i = 0; i < 8; i++){
for(int j = i +1; j < 8; j++){
if(rookArr[i] == rookArr[j]){
lastCorrect = false;
}
}
}
if(lastCorrect)
System.out.println("#" + test_case+" " + "yes");
else
System.out.println("#" + test_case+" " + "no");
}
else{
System.out.println("#" + test_case+" " + "no");
}
}
}
문제 해결의 경우 for문을 돌려 풀었는데 더 나은 방법이 존재할 것이다.