imported>molid7 |
imported>molid7 |
| Line 1: |
Line 1: |
| import java.util.Scanner;
| | // 잘못 만든 페이지;;;;;; |
|
| |
| class Case {
| |
| int m;
| |
| int n;
| |
| char[][] grid;
| |
| int k;
| |
| String[] str;
| |
| int index;
| |
| /*int[][] direction= {{-1,-1}, {0,1}, {1,1},
| |
| {-1,-1}, {0,-1}, {1,-1},
| |
| {-1,0},
| |
| {1,0}};*/
| |
| int[] y = {-1, -1, -1, 0, 1, 1, 1, 0};
| |
| int[] x = {-1, 0, 1, 1, 1, 0, -1, -1};
| |
| int length;
| |
|
| |
| Case(int m, int n, char[][] grid, int k, String[] str) {
| |
| this.m = m;
| |
| this.n = n;
| |
| this.grid = grid.clone();
| |
| this.k = k;
| |
| this.str = str.clone();
| |
| /*index = 0;*/
| |
| length = 1; //첫 단어
| |
| /*direction = new int[2][4];*/
| |
|
| |
| }
| |
| void output() {
| |
| for(int i=0; i<str.length; i++) { //찾을 단어 개수만큼
| |
| index = 0; //다음 단어의 첫 글자
| |
| for(int row=0; row<m; row++) {
| |
| for(int col=0; col<n; col++) {
| |
| if(grid[row][col] == str[i].charAt(index)) { // 첫 단어가 맞으면
| |
| /*System.out.println(str[i].charAt(index));
| |
| System.out.println((row+1) + " " + (col+1));*/
| |
| System.out.println("444 : " + (row+1) + " " + (col+1) );
| |
|
| |
| if(check(grid, row, col, str[i])) {
| |
| System.out.println();
| |
| System.out.println("check: " + (row+1) + " " + (col+1));
| |
| System.out.println();
| |
| }
| |
|
| |
| length =1;
| |
| }
| |
| }
| |
| }
| |
| }
| |
| }
| |
|
| |
| boolean check(char[][] grid, int row, int col, String str) {
| |
| int idx = 1;
| |
| int temp_r;
| |
| int temp_c;
| |
| int cnt = str.length();
| |
|
| |
| for(int i=0; i<8; i++) { //각 방향에 대해서
| |
| idx =1;
| |
| temp_r = row;
| |
| temp_c = col;
| |
| length=1;
| |
| cnt = str.length();
| |
|
| |
| System.out.println();
| |
| System.out.println(str);
| |
| System.out.println();
| |
|
| |
| while(0 < cnt--) {
| |
| temp_r += y[i]; //방향이동
| |
| temp_c += x[i];
| |
|
| |
| System.out.println("111 "+ temp_r + " " + temp_c);
| |
|
| |
| if(temp_r >= 0 && temp_r < m && temp_c >=0 && temp_c <n) {
| |
| System.out.println("222");
| |
| System.out.println("idx = " + idx);
| |
| if(grid[temp_r][temp_c] == str.charAt(idx)) {
| |
| System.out.println("333");
| |
| length++;
| |
| idx++;
| |
| }
| |
| }
| |
| }
| |
| if(length == str.length()) return true;
| |
| }
| |
|
| |
| return false;
| |
| }
| |
| }
| |
| public class Waldorf {
| |
| public static void main(String ar[]) {
| |
| Scanner sc = new Scanner(System.in);
| |
| int num = sc.nextInt();
| |
| int m;
| |
| int n;
| |
| char[][] grid;
| |
| int k;
| |
| String[] str;
| |
|
| |
| // System.out.println(num); /////////
| |
|
| |
| Case[] caseArr = new Case[num];
| |
| for(int i=0; i<caseArr.length; i++) {
| |
| m = sc.nextInt();
| |
| n = sc.nextInt();
| |
| // System.out.println(m); /////////
| |
| // System.out.println(n); /////////
| |
| sc.nextLine();
| |
| grid = new char[m][n];
| |
| for(int row=0; row<m; row++) {
| |
| grid[row] = sc.nextLine().toLowerCase().toCharArray().clone();
| |
| // System.out.println(grid[row]);
| |
| }
| |
|
| |
| /*for(int a=0; a<m; a++) {
| |
| for(int b=0; b<n; b++) {
| |
| System.out.print(grid[a][b]);
| |
| }
| |
| System.out.println();
| |
| }*/
| |
|
| |
| k = sc.nextInt();
| |
| // System.out.println(k);
| |
| str = new String[k];
| |
| sc.nextLine();
| |
| for(int j=0; j<k; j++)
| |
| str[j] = sc.nextLine().toLowerCase();
| |
|
| |
| caseArr[i] = new Case(m, n, grid, k, str);
| |
| caseArr[i].output();
| |
| }
| |
| }
| |
| }
| |
|
| |
|