Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: main.c
- * Author: alulab11
- *
- * Created on 20 de junio de 2014, 11:31 AM
- */
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 8
- /*void imprimirTablero(char A[MAX][MAX],int tam){
- int i,j;
- for(i=0;i<tam;i++){
- for(j=0;j<tam;j++){
- printf("%c",A[i][j]);
- }
- }
- printf("\n");
- }*/
- int esValido(char A[MAX][MAX],int tam, int fil, int col){
- int i;
- if (A[fil][col]== 'X')
- return 0;
- for(i=col-1;i>=0;i--){
- if (A[fil][i] == 'X') break;
- if (A[fil][i] == 'T') return 0;
- }
- for(i=fil-1;i>=0;i--){
- if (A[i][col] == 'X') break;
- if (A[i][col] == 'T') return 0;
- }
- return 1;
- }
- void dontGetRooked(int fil, int col, char A[MAX][MAX],int tam,
- int *cantTorres, int *maxTorres){
- int nuevoX,nuevoY;
- if (col == tam){
- if(*cantTorres>*maxTorres)
- *maxTorres = *cantTorres;
- return;
- }
- if (fil = tam){
- nuevoY++;
- nuevoX=0;
- }else{
- nuevoX++;
- }
- if (esValido(A,tam,fil,col)){
- A[fil][col] = 'T';
- (*cantTorres)++;
- dontGetRooked(nuevoX,nuevoY,A,tam,cantTorres,maxTorres);
- A[fil][col]='.';
- (*cantTorres)--;
- }
- dontGetRooked(nuevoX,nuevoY,A,tam,cantTorres,maxTorres);
- return;
- }
- /*
- *
- */
- int main(int argc, char** argv) {
- char c;
- int tam;
- char A[MAX][MAX];
- while(scanf("%d",&tam) != EOF){
- if (tam>0){
- int i,j;
- for (i=0;i<tam;i++){
- for(j=0;j<tam;j++){
- scanf(" %c",&c);
- A[i][j]=c;
- }
- }
- dontGetRooked(0,0,A,tam,0,0);
- }
- }
- //imprimirTablero(A,tam);
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement