Dev.baelanche

[백준 2804] 크로스워드 만들기 본문

Data Structure & Algorithm/PS - JAVA

[백준 2804] 크로스워드 만들기

baelanche 2019. 4. 12. 21:14
반응형

 

가장 처음 겹치는 글자의 인덱스를 구하여 배열의 가로, 세로의 인덱스로 사용한다.

 

 

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        int x = 0;
        int y = 0;
        char c[][] = new char[b.length()][a.length()];
        
        for(int i=0; i<b.length(); i++) {
            for(int j=0; j<a.length(); j++) {
                c[i][j] = '.';
            }
        }
        
        boolean s = false;
        for(int i=0; i<a.length(); i++) {
            for(int j=0; j<b.length(); j++) {
                if(a.charAt(i) == b.charAt(j) && !s) {
                    s = true;
                    x = j; y = i;
                }
            }
        }
        
        c[x] = a.toCharArray();
        for(int i=0; i<b.length(); i++)
            c[i][y] = b.charAt(i);
        
        for(int i=0; i<b.length(); i++) {
            for(int j=0; j<a.length(); j++) {
                System.out.print(c[i][j]);
            }
            System.out.println();
        }
        sc.close();
    }
}
반응형

'Data Structure & Algorithm > PS - JAVA' 카테고리의 다른 글

[백준 1260] DFS와 BFS  (0) 2019.04.12
[백준 10409] 서버  (0) 2019.04.12
[백준 5533] 유니크  (0) 2019.04.12
[백준 5212] 지구 온난화  (0) 2019.04.11
[백준 10539] 수빈이와 수열  (0) 2019.04.11
Comments