Java > Prologin TTY

TitrePrologin TTY
Postée le22-08-2009
Affichée433
Mini-lien
Description

Cadeau =B

EtatContient des erreurs. Contient des erreurs.
Code d'insertion
Options
Afficher les numéros de lignes  Mettre la source en plein ecran  Selectionner la source  Partager sur Facebook 
Téléchargement Telecharger en format txt  Telecharger en format pdf  Telecharger en format java
Plein ecran
import java.util.ArrayList;
import java.util.Scanner;


class Main
{
  private static int tty(int h, int l, int y_tty, int x_tty, int y_gam, int x_gam, char[][] carte, boolean[][] visites)
  {
     if ( x_tty < 0 || y_tty < 0 || x_tty >= l || y_tty >= h)
     {
         return 0 ;
     }

  if(visites[y_tty][x_tty])
    return 0 ;
 
  visites[y_tty][x_tty] = true ;
 
  if( x_tty == x_gam && y_tty == y_gam)
      return 1 ;

  if (carte[y_tty][x_tty] == 'X')
      return 0 ;

       
      if(tty(h, l, y_tty+1, x_tty, y_gam, x_gam, carte, visites) == 1)
          return 1 ;
      if(tty(h, l, y_tty-1, x_tty, y_gam, x_gam, carte, visites) == 1)
          return 1 ;
     
     if(tty(h, l, y_tty, x_tty+1, y_gam, x_gam, carte, visites)  == 1)
          return 1 ;
      if(tty(h, l, y_tty, x_tty-1, y_gam, x_gam, carte, visites)  == 1)
          return 1 ;

      return 0 ;

   }
  public static void main(String args[]) throws java.io.IOException
  {
    Scanner scanner = new Scanner(System.in);
    int h;
    int l;
    int y_tty;
    int x_tty;
    int y_gam;
    int x_gam;
    char[][] carte;


    h = scanner.nextInt();
    scanner.nextLine();

    l = scanner.nextInt();
    scanner.nextLine();

    boolean[][] visites = new boolean[h][l];

    y_tty = scanner.nextInt();
    scanner.nextLine();

    x_tty = scanner.nextInt();
    scanner.nextLine();

    y_gam = scanner.nextInt();
    scanner.nextLine();

    x_gam = scanner.nextInt();
    scanner.nextLine();

    carte = new char[h][l];
    for (int i = 0; i < h; i++)
    {
      String tmp = scanner.next();
      for (int j = 0; j < l; j++)
        {
        carte[i][j] = tmp.charAt(j);
        visites[i][j] = false ;
       }
    }

    System.out.println(tty(h, l, y_tty, x_tty, y_gam, x_gam, carte, visites));
  }
}