//--------------------------------------------------------------------------- #include #include //--------------------------------------------------------------------------- int GetRandom(int R,float P) { float Ran = ((float)rand())/((float)RAND_MAX); if( Ran < P ) { return R; } return random(R); } ///***************************************************************************** void MapaAleatorio(int OrigenRen,int OrigenCol,int Ren,int Col,float P) { FILE *Input = fopen("Input.txt","w+t"); int i,j,Count; Count = 0; int **Matriz = new int*[Ren]; for(i = 0; i < Ren; i++) { Matriz[i] = new int[Col]; for(j = 0; j < Col; j++) { Matriz[i][j] = GetRandom(4,P); if( Matriz[i][j] != 4 ) { Count++; } } } fprintf(Input,"%d",Count); for(i = 0; i < Ren; i++) { for(j = 0; j < Col; j++) { if( Matriz[i][j] != 4 ) { fprintf(Input,"\n%d %d %d",OrigenRen+i,OrigenCol+j,Matriz[i][j]); } } } fclose(Input); } ///***************************************************************************** void Mapea(int N, int *CoorY,int *CoorX,int *Tipo) { FILE *Output; char Letra[] = {'A','N','R','D','*'}; char **Matriz; int Ren,Col,i,j,MinX,MaxX,MinY,MaxY; MinX = 12000; MaxX = 0; MinY = 12000; MaxY = 0; for(i = 0; i < N; i++) { if( CoorX[i] < MinX ) { MinX = CoorX[i]; } if( MaxX < CoorX[i] ) { MaxX = CoorX[i]; } if( CoorY[i] < MinY ) { MinY = CoorY[i]; } if( MaxY < CoorY[i] ) { MaxY = CoorY[i]; } } Ren = MaxY - MinY + 1; Col = MaxX - MinX + 1; Matriz = new char*[Ren]; for(i = 0; i < Ren; i++) { Matriz[i] = new char[Col]; for(j = 0; j < Col; j++) { Matriz[i][j] = '*'; } } for(i = 0; i < N; i++) { Matriz[CoorY[i]-MinY][CoorX[i]-MinX] = Letra[Tipo[i]]; } Output = fopen("output.txt","w+t"); for(i = 0; i < Ren; i++) { for(j = 0; j < Col; j++) { fprintf(Output,"%c",Matriz[i][j]); } fprintf(Output,"\n"); } fclose(Output); for(i = 0; i < Ren; i++) { delete[] Matriz[i]; } delete[] Matriz; } ///***************************************************************************** int main() { //MapaAleatorio(5000,1000,50,70,0.8); int i,N,*CoorX,*CoorY,*Tipo; FILE *Input = fopen("Input.txt","r+t"); fscanf(Input,"%d",&N); CoorY = new int[N]; CoorX = new int[N]; Tipo = new int[N]; for(i = 0; i < N; i++) { fscanf(Input,"%d %d %d",&CoorY[i],&CoorX[i],&Tipo[i]); } fclose(Input); Mapea(N,CoorY,CoorX,Tipo); delete[] CoorY; delete[] CoorX; delete[] Tipo; return 0; } //---------------------------------------------------------------------------