|
Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.
Mensajes - danime
Páginas: [1]
1
« en: Martes 26 de Diciembre de 2006, 13:52 »
gracias
2
« en: Martes 26 de Diciembre de 2006, 08:22 »
hola necesito que me ayuden
esta es la parte de un programa que necesita parametros en la funcion principal
int main (int argc, char *argv[]) int dim, row, column; char vs;
row = atoi(argv[2]); column = atoi(argv[3]); vs = atoi(argv[4]); dim= atoi(argv[1]);
los parametros a ingresar son por ejemplo 5 1 1 V
el problema es que no reconoce el caracter
como puedo arreglarlo???????
y otra pregunta
si yo quiero ejecutarlo en linux poniendo ./nombre 5 1 1 V debo cambiar los indices de los argumentos??, es decir, se toma ./nombre como un argumento???
3
« en: Lunes 11 de Diciembre de 2006, 23:28 »
le pongo depurar y se abre la pantalla y se cierra altiro...
== no c para que sirve hacer eso pero lo hice
4
« en: Lunes 11 de Diciembre de 2006, 22:52 »
hola, ya havia preguntado hacerca del mismo programa un caballo debe recorrer un tablero de dimension n comenzando de la fila f y columna c ... ya arregle todos los errores que tenia pero al ejecutarlo falla alguien me podria decir cual es el error?? porfavorrr necesito entregarlo hoy antes de las 24:00 el programa tiene esta libreria que hay que incluirla en la misma carpeta en donde esta el programa /* These are for time measures */ /* * Adjust this to the clock freq. of the machine where time intervals * are computed. */ #define CLOCK 350 typedef struct { unsigned long hi; unsigned long lo; } time_586; #define ttime(x) \ __asm__ __volatile__("rdtsc" : "=d" (x.hi), "=a" (x.lo)) static inline double time_diff(time_586 b, time_586 a) { double db,da,res; db = (double)b.hi*(double)(1<<16)*(double)(1<<16)+(double)b.lo; da = (double)a.hi*(double)(1<<16)*(double)(1<<16)+(double)a.lo; if (db < da) res = ((double)(1<<16)*(double)(1<<16)*(double)(1<<16)*(double)(1<<16)+db-da) /(double)CLOCK; else res = (db-da)/(double)CLOCK; return res; } *************************************************** AKI ESTA EL PROGRAMA!!!!! #include <stdlib.h> #include <stdio.h> #include <string.h> #include <time.h> #include "Time.h" typedef struct { int fila;/*fila en donde esta ubicado actualmente*/ int columna;/*columna donde esta actualmente*/ int ganador;/*opcion del movimiento ganador*/ int cuantos;/*cuantas ociones quedaron*/ int opciones[7];/*movimientos posibles que quedaron*/ } nodo; typedef struct { int top, cont; nodo *pila; }stack; typedef struct{ int cuantos; int mpi;/*numero elegido al azar*/ int mpj;/*opcion correspondiente al numero anterior*/ int opciones[8];}movpos;/*movimientos posibles*/ void init_stack( stack *a, int n) { int i,j; a->top=-1; a->pila=calloc(n*n,sizeof(nodo));/*inicia el stack con memoria n*n */ for(i=0; i<(n*n); i++) { for(j=0; j<8; j++) a->pila .opciones[j]= 0;} }
void opc (int f, int c, movpos *pos, int **m ) { int opi,opj=0; int mov[8][2]={{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1}};/*formula para calcular movimientos*/ for(opi=0; opi<8; opi++) { if( m[f+1+mov[opi][0]][c+1+mov[opi][1]]==0) { pos->opciones[opj]=opi+1; opj++; pos->cuantos++;} } }
void push(stack*s,movpos *q,int **m) { int pk; int mov[8][2]={{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1}}; s->top=s->top+1; s->pila[s->top].fila =s->pila[s->top-1].fila +mov[q->mpj-1][0]; s->pila[s->top].columna=s->pila[s->top-1].columna +mov[q->mpj-1][1]; s->pila[s->top].ganador=q->mpj; s->pila[s->top].cuantos=q->cuantos-1;
for(pk=0;pk<q->cuantos;pk++) { int l=0;
if(pk==q->mpi) pk++; else { s->pila[s->top].opciones[l]=q->opciones[pk]; l++; } } s->cont++; m[s->pila[s->top].fila+1][s->pila[s->top].columna+1]=s->cont; }
void pop(stack*s,movpos*q, int ** { movpos *p; int popk; b[s->pila[s->top].fila+1][s->pila[s->top].columna+1]=0; s->top=s->top-1; opc(s->pila[s->top].fila,s->pila[s->top].columna, q,B);
p->cuantos=q->cuantos-1;
p->mpi=p->mpj=0;
for( popk=0;popk< p->cuantos;popk++) { int l=0;
if(popk==s->pila[s->top+1].ganador) popk++; else { p->opciones[l]=q->opciones[popk]; l++; } } q =p;
}
int main (int dim, int row, int column, int vs) { int i, j,k;
double Etime, Esec; time_586 inicio, fin;
if(dim>4) {if((row<=dim && row<0 ) && (column<=dim && column>0)) { if((vs=='V')||(vs=='S')) { stack *horse; int ** matriz; movpos *q;
init_stack(horse,dim); matriz= calloc(dim+4, sizeof(int *)); for(i=0; i<dim+4; i++) matriz=calloc(dim+4, sizeof(int) );
for(i=0; i<dim+4;i++) { matriz[0]=matriz[1]=matriz[0]=matriz[1]=matriz[dim+2]=1; matriz[dim+3]=matriz[dim+3]=matriz[dim+2]=1; } q->cuantos=q->mpi=q->mpj=0; for(i=0; i<7; i++) q->opciones=0;
horse->top=horse->top+1; horse->pila[horse->top].ganador=0; horse->pila[horse->top].cuantos=0; horse->pila[horse->top].fila=row; horse->pila[horse->top].columna=column; horse->cont++;
matriz[row+1][column+1]=1; do{ ttime(inicio); q->cuantos=q->mpi=q->mpj=0; for(i=0; i<7; i++) q->opciones=0;
opc(horse->pila[horse->top].fila, horse->pila[horse->top].columna, q, matriz);
if(q->cuantos==0) { while(q->cuantos==0) pop(horse,q,matriz); q->mpi=rand()%q->cuantos; q->mpj=q->opciones[q->mpi]; push(horse, q, matriz); } else { if(q->cuantos==1) q->opciones[0]=q->mpj; if(q->cuantos>1) { srand(time(NULL)); q->mpi=rand()%q->cuantos; q->mpj=q->opciones[q->mpi]; }
push(horse, q, matriz); }
} while(horse->cont==dim*dim);
ttime(fin); Etime = time_diff(fin,inicio) ; Esec = Etime / 1000000;
if(vs=='S') printf("%f",Esec); if(vs=='V') { stack *b; init_stack(b,dim); j=0; for(i=(dim*dim)-1;i>-1;i--) { horse->pila.fila=b->pila[j].fila; horse->pila.columna=b->pila[j].columna; horse->pila.ganador=b->pila[j].ganador; horse->pila.cuantos=b->pila[j].cuantos; for(k=0;k<8;k++) horse->pila.opciones[k]=b->pila[j].opciones[k]; j++; }
printf("%f", Esec); for( i=(dim*dim)-1;i>-1;i--) printf("%d %d %d\n",b->pila.ganador,b->pila.fila,b->pila.columna);
} } }return 1;} printf("Error"); }
ojalá me puedan ayudar
5
« en: Lunes 4 de Diciembre de 2006, 01:10 »
hola a todos queria saber si me podian ayudar con este programa se supone que debe recorrer el tablero de ajedres de dimension n desde la posicion f, c este problema es muy conocido pero me pidieron que lo hiciera con stack ademas debe mostrar el tiempo me da un error que no entiendo pointer to structure require on left of ->or ->* #include<stdlib.h> #include<stdio.h> #include"time.h" typedef struct { int fila, columna, ganador, cuantos; float tiempo; int opciones[8];}nodo; typedef struct { int tope, cuantos; nodo *pila; }stack; typedef struct{ int ** matriz; }mat; typedef struct{ int mov[8][2]; } coordenadas; typedef struct{ int cuantos,i,j; int opciones[7];}movpos; void init_stack( stack *a, int n) { int i,j; a->tope=-1; a->pila=calloc(n*n,sizeof(nodo)); } void push(stack*s,movpos q,coordenadas a, mat ** { int k; s->tope=s->tope+1; s->pila[s->tope]->fila = (s->pila[s->tope-1]->fila+ a->mov[q.j-1][0]); s->pila[s->tope]->columna =(s->pila[s->tope-1]->columna + a->mov[q.j-1][1]); s->pila[s->tope]->ganador=q.j; s->pila[s->tope]->cuantos=q.cuantos-1; for(k=0;k<8;k++) { int l=0; if(k==q.i) k++; else { s->pila[s->tope]->opciones[l]=q.opciones[k]; l++; } s->cuantos++; } b->matriz[s->pila[s->tope]->fila+1][s->pila[s->tope]->columna+1]=1; } void pop(stack*s,movpos*q, mat ** b, coordenadas a) { int k; movpos *p; b->matriz[s->pila[s->tope]->fila+1][s->pila[s->tope]->columna+1]=0; s->tope=s->tope-1; opc(s->pila[s->tope]->fila,s->pila[s->tope]->columna, &q, a, &&b) p->cuantos=q->cuantos-1; p->i=p->j=0; for( k=0;k<8;k++) { int l=0; if(k==s->pila[s->tope]->ganador) k++; else { p->opciones[l]=q->opciones[k]; l++; } } q =p; } void opc (int f, int c, movpos *pos, coordenadas a, mat ** b ) { int i,j=0; for(i=0; i<8; i++) { if(ocupado((f+a.mov [0]),(c+a.mov[1]), &&b)== 0) { pos->opciones[j]=i+1; j++; pos->cuantos++;} } }
int ocupado(int f, int c, mat ** { if(b->matriz[f+1][c+1]==1) return (1);
if(b->matriz[f+1][c+1]==0) return (0); }
int verifica(int n, int f, int c, int o) {
if(f>n||f<1||c>n||c<1) printf("ingresar coordenadas validas"); return 0;
if(o!='V'||o!='S') printf("ingresar opcion valida") return 0; if(n<5) printf("ingresar n > 4") return 0;
else return 1; )
void init_matriz( mat ** { b->matriz= calloc(n+4, sizeof(int *)); for(i=0; i<f; i++) b->matriz=calloc((n+a, sizeof(int)); for(int i=0; i<n+4; i++) b->matriz[0]= b->matriz[1]= b->matriz[0]= b->matriz[1]= b->matriz[n+2]= b->matriz[n+3]= b->matriz[n+3]= b->matriz[n+2]=1;
}
void main(int n, int f, int c, int o) {
if(verifica(n,f,c,o)==1) { stack *a; init_stack(&a,n);
for(i=0; i<(n*n); i++) { for(j=0; j<8; j++) a->pila->opciones[j]= 0;}
coordenadas * movimientos
movimientos->mov[0][0]= movimientos->mov[7][0]= movimientos->mov[5][1]= movimientos->mov[6][1]= -2; movimientos->mov[1][0]= movimientos->mov[6][0]= movimientos->mov[4][1]= movimientos->mov[7][1]= -1; movimientos->mov[2][0]= movimientos->mov[5][0]= movimientos->mov[0][1]= movimientos->mov[5][1] =1; movimientos->mov[1][1]= movimientos->mov[2][1]= movimientos->mov[3][0]= movimientos->mov[4][0]= 2;
mat tablero; init_matriz(&&tablero);
movpos *q q->cuantos=q->i=q->j=0; int i; for(i=0; i<7; i++) q->opciones=0;
time_586 tstart, tend; double Etime, Esec,ttotal=0; a->tope=a->tope+1; a->pila[a->tope]->ganador=0; a->pila[a->tope]->cuantos=0; a->pila[a->tope]->fila=f; a->pila[a->tope]->columna=c; a->pila[a->tope]->tiempo=0; a->cuantos++; tablero->matriz[f+1][c+1]=1;
do{ time(tstart); opc(a.pila[a.tope].fila, a.pila[a.tope].columna, &q, movimientos)
if(q->cuantos==0) { while(q->cuantos==0) pop(&a, &q, &&tablero, movimientos); q->i=rand()%q.cuantos; q->j=q.opciones[q->i];
push(&a, q, movimientos, &&tablero ) time(tend); Etime = time_diff(tend,tstart); Esec = Etime / 1000000; ttotal=ttotal+Esec; a->pila[a->tope]->tiempo=ttotal; } else { if(q->cuantos==1) q->opciones if(q->cuantos>1) { srand(time(NULL)); q->i=rand()%q->cuantos; q->j=q->opciones[q->i]; }
push(&a, q, movimientos, &&tablero) time(tend); Etime = time_diff(tend,tstart); Esec = Etime / 1000000; ttotal=ttotal+Esec; a->pila[a->tope]->tiempo=ttotal; }while(a.cuantos==n*n); if(o==S) printf("%f",Esec); if(o==V) { stack b init_stack(&b,n); int j=0; for(int i=(n*n)-1;i>-1;i--) { a.pila.fila=b->pila[j]->fila; a.pila.columna=b->pila[j]->columna; a.pila.ganador=b->pila[j]->ganador; a.pila.cuantos=b->pila[j]->cuantos; a.pila.tiempo=b->pila[j]->tiempo; for(int k=0;k<8;k++) { a.pila.opciones[k]=b->pila[j]->opciones[k]; j++ } } for(int i=(n*n)-1;i>-1;i--) { printf("%f %d %d %\n",b->pila->tiempo,b->pila->ganador,b->pila->fila,b->pila->columna;) } }
}
}
el erro me sale en casi todas las lineas donde ocupo ->
ayudenme porfavor!!!
Páginas: [1]
|
|
|