Advertisement
pmanriquez93

Don´t Get Rooked

Jun 20th, 2014
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MAX 4
  4. char tab[MAX][MAX];
  5. void leerTab(char tab[MAX][MAX], int tam){
  6.     int i,j;
  7.     for(i=0;i<tam;i++)
  8.         for(j=0;j<tam;j++){
  9.             int car;
  10.             scanf(" %c",&tab[i][j]);
  11.        }
  12.            
  13. }
  14. int max(int value1, int value2){
  15.     if (value1>value2) return value1;
  16.     return value2;
  17. }
  18. void buscaPo(int fil, int col,int tam,int* sx, int *sy){
  19.    *sx = fil+1;
  20.    *sy = col;
  21.    if (*sx == tam){
  22.        *sx = 0;
  23.        *sy = col+1;
  24.    }
  25. }
  26. int isSafe(int fil, int col,char tab[MAX][MAX], int tam){
  27.     int i;
  28.     if (tab[fil][col] == 'X' || tab[fil][col] == 'T')
  29.         return 0;
  30.     for(i=col-1;i>=0;i--){
  31.         if (tab[fil][i] == 'X') break;
  32.         if (tab[fil][i] == 'T') return 0;
  33.     }
  34.     for(i=fil-1;i>=0;i--){
  35.        if (tab[i][col] == 'X') break;
  36.        if (tab[i][col] == 'T') return 0;
  37.     }
  38.     return 1;    
  39. }
  40. void llena(int fil,int col,int tam, char tab[MAX][MAX],int *ntorres,int *maxi){
  41.     if (col == tam){
  42.         *maxi = max(*ntorres,*maxi);
  43.         return;
  44.     }
  45.     int sig_x,sig_y;
  46.    
  47.     buscaPo(fil,col,tam,&sig_x,&sig_y);
  48.     if ( isSafe(fil,col,tab,tam) ){
  49.         tab[fil][col] = 'T';
  50.         (*ntorres)++;
  51.         llena(sig_x,sig_y,tam,tab,ntorres,maxi);
  52.         tab[fil][col] = '.';
  53.         (*ntorres)--;
  54.     }
  55.     llena(sig_x,sig_y,tam,tab,ntorres,maxi);
  56. }
  57. int main(int argc, char** argv) {
  58.     int tam;
  59.    while ( scanf("%d",&tam) != EOF){
  60.        if (tam > 0){
  61.            leerTab(tab,tam);
  62.            int torres = 0, mtorres = 0;
  63.            llena(0,0,tam,tab,&torres,&mtorres);
  64.            printf("%d\n",mtorres);
  65.        }        
  66.     }
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement