#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv){
FILE *out;
int i, j;
int fieldWidth;
int fieldHeight;
int differentNumbers;
double movesImportance;
double ditanceImportance;
int **field;
srand( time(NULL) );
sscanf(argv[2], "%d", &fieldWidth);
sscanf(argv[3], "%d", &fieldHeight);
sscanf(argv[4], "%d", &differentNumbers);
sscanf(argv[5], "%lf", &movesImportance);
sscanf(argv[6], "%lf", &ditanceImportance);
field = malloc( fieldWidth*sizeof(int*) );
for(i=0; i<fieldWidth; i++){
field[ i ] = malloc( fieldHeight*sizeof(int) );
}
out = fopen(argv[1], "wt");
fprintf(out, "%d %d %d %lf %lf\n", fieldWidth, fieldHeight, differentNumbers, movesImportance, ditanceImportance);
for(j=0; j<fieldHeight; j++){
for(i=0; i<fieldWidth; i++){
field[ i ][j] = 1 + rand()%differentNumbers;
fprintf(out, "%d ", field[ i ][j]);
}
fprintf(out, "\n");
}
for(j=0; j<fieldHeight; j++){
for(i=0; i<fieldWidth; i++){
int k = rand() % fieldWidth;
int l = rand() % fieldHeight;
int temp = field[ i ][j];
field[ i ][j] = field[k][l];
field[k][l] = temp;
}
}
for(j=0; j<fieldHeight; j++){
for(i=0; i<fieldWidth; i++){
fprintf(out, "%d ", field[ i ][j]);
}
}
fprintf(out, "\n");
fclose( out );
for(i=0; i<fieldWidth; i++){
free( field[ i ] );
}
free( field );
return( 0 );
}
|