Advertisement
pmanriquez93

Don´t Get Rooked

Jun 20th, 2014
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.89 KB | None | 0 0
  1. /*
  2.  * File:   main.c
  3.  * Author: alulab11
  4.  *
  5.  * Created on 20 de junio de 2014, 11:31 AM
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #define MAX 4
  11.  
  12. void buscaPo(int fil, int col,int tam,int* sx, int *sy){
  13.    *sx = fil+1;
  14.    *sy = col;
  15.    if (*sx == tam){
  16.        *sx = 0;
  17.        *sy = col+1;
  18.    }
  19. }
  20.  
  21. int esValido(char A[MAX][MAX],int tam, int fil, int col){
  22.     int i;
  23.     if (A[fil][col]== 'X'|| A[fil][col]=='T')
  24.         return 0;
  25.     for(i=col-1;i>=0;i--){
  26.         if (A[fil][i] == 'X') break;
  27.         if (A[fil][i] == 'T') return 0;
  28.     }
  29.     for(i=fil-1;i>=0;i--){
  30.        if (A[i][col] == 'X') break;
  31.        if (A[i][col] == 'T') return 0;
  32.     }
  33.     return 1;    
  34.    
  35. }
  36.    
  37.  
  38. void dontGetRooked(int fil, int col, char A[MAX][MAX],int tam,
  39.                   int *cantTorres, int *maxTorres){
  40.     int nuevoX,nuevoY;
  41.     if (col == tam){
  42.         if(*cantTorres > *maxTorres)
  43.             *maxTorres = *cantTorres;
  44.         return;
  45.     }
  46.     buscaPo(fil,col,tam,&nuevoX,&nuevoY);
  47.  
  48.     if (esValido(A,tam,fil,col)){
  49.         A[fil][col] = 'T';
  50.         (*cantTorres)++;
  51.         dontGetRooked(nuevoX,nuevoY,A,tam,cantTorres,maxTorres);
  52.         A[fil][col]= '.';
  53.         (*cantTorres)--;
  54.     }
  55.     dontGetRooked(nuevoX,nuevoY,A,tam,cantTorres,maxTorres);        
  56.     return;
  57. }
  58. int main(int argc, char** argv) {
  59.     char c;
  60.     int tam;
  61.     char A[MAX][MAX];
  62.     int maxTorres,contTorres;
  63.     scanf("%d",&tam);
  64.     while(tam>0){
  65.         maxTorres = 0;
  66.         contTorres = 0;
  67.                 int i,j;
  68.                 for (i=0;i<tam;i++){
  69.                         for(j=0;j<tam;j++){
  70.                                 scanf(" %c",&A[i][j]);
  71.                          }
  72.                 }
  73.                
  74.                 dontGetRooked(0,0,A,tam,&contTorres,&maxTorres);
  75.                 printf("%d\n",maxTorres);
  76.        
  77.         scanf("%d",&tam);
  78.     }
  79.     return 0;  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement