1343 폴리오미노 문제 링크
문제

#1
import java.awt.*;
import java.io.*;
import java.util.*;
class Main {
static String poly;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
poly = br.readLine();
System.out.println(board());
}
static String board() {
int countX = 0;
String answer = "";
for(int i=0; i<poly.length(); i++) {
if(poly.charAt(i) == 'X') {
countX++;
}
else if(poly.charAt(i) == '.') {
if(countX != 0) {
for (int j = 0; j < countX / 4; j++) {
answer += "AAAA";
}
countX = countX % 4;
for (int j = 0; j < countX / 2; j++) {
answer += "BB";
}
if (countX % 2 != 0) return "-1";
countX = 0;
}
answer += ".";
}
}
if(countX != 0) {
for (int j = 0; j < countX / 4; j++) {
answer += "AAAA";
}
countX = countX % 4;
for (int j = 0; j < countX / 2; j++) {
answer += "BB";
}
if (countX % 2 != 0) return "-1";
countX = 0;
}
return answer;
}
}

- 성공!
- 근데 코드가 넘 더럽다..
- 김주희 코드 보니까 replace로 풀면 되더라,,,,