Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package algorithms;
- import java.util.*;
- public class Main {
- static HashMap<String, String> map = new HashMap<String, String>();
- static Boolean[][] arr2 = new Boolean[8][8];
- public static void find(char[][] arr, int row, int column,int moves) {
- if ((row!=7||column!=0)&&arr[row][column] != '.') {
- return;
- }
- if (row == 0 && column == 7) {
- System.out.println("WIN");
- return;
- }
- arr2[row][column]= true ;
- for (String i : map.keySet()) {
- int index1 = (int)i.charAt(0);
- int index2 = (int)i.charAt(2);
- if(index1+moves==row&&index2==column) {
- return ;
- }
- }
- moves++;
- if (row != arr.length - 1) {
- if(a)
- find(arr, row + 1, column, moves);
- }
- if (column != arr[0].length - 1) {
- find(arr, row, column + 1, moves);
- }
- if (row != 0) {
- find(arr, row - 1, column, moves);
- }
- if (column != 0) {
- find(arr, row, column - 1, moves);
- }
- return;
- }
- public static void main(String[] args) {
- int index=0;
- Scanner s = new Scanner(System.in);
- char[][] arr = new char[8][8];
- for (int k = 0; k < 8; k++) {
- String line = s.next();
- for (int j = 0; j < 8; j++) {
- arr[k][j] = line.charAt(j);
- if(arr[k][j]=='S') {
- map.put("0", k+"-"+j);
- index++;
- }
- }
- }
- find(arr, 7,0 , 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement