Esempio n. 1
0
void random(int n, int m, int mat[n][m]){
int a, b, ind;
a = randomenter1();
b = randomenter2();
fillRand(n, m, mat, a, b);
printMatrix(n, m, mat);
}
Esempio n. 2
0
File: 1.c Progetto: faithche/tasks
int main(void) {
	int n , m;
	printf ("vvedite razmer matritsu:\n");
	fflush(stdin);
	scanf (" %i %i" , &n, &m);
	int arr[n][m];
	fillRand(n , m , arr);
	printArr( n , m , arr);
	return 0;
}
Esempio n. 3
0
World makeRandomWorld(int rows, int cols, int amount_cells) {
  World w;
  w.rows = rows;
  w.cols = cols;
  w.cells = (byte*) malloc(w.rows*w.cols);
  if (w.cells == NULL) return w;
  
  fillRand(&w, amount_cells);
  
  return w;
}
Esempio n. 4
0
int main(void){
srand((unsigned)time(NULL));
int n, m, c;
background();
hello();
background();
n = firstEnter1();
m = firstEnter2();
background();
int mat[n][m];
fillRand(n, m, mat, -50, 50);
printMatrix(n, m, mat);
command(n, m, mat);
getch();
return EXIT_SUCCESS;
}
Esempio n. 5
0
int main(){
	int aSize = 0;
	cnt = 0;
	cout<<"Enter array size: ";cin>>aSize;
	int *strArray = new int[aSize];
	int *orgArray = new int[aSize];
	int search = aSize;
	//getArray(strArray,aSize);
	fillRand(strArray,aSize);
	printAr(strArray,aSize);
	copyArray(strArray,orgArray,aSize);
	cout<<"******** standard search **********"<<endl;
	cout<<"Found "<<search<<" at ";
	cout<<standardSearch(strArray,aSize, search);
	cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl;
	
	cout<<"******** binary search **********"<<endl;
	cout<<"Found "<<search<<" at ";
	selectionSort(strArray,aSize);
	cout<<binarySearch(strArray,aSize,search);
	cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl;
	copyArray(orgArray,strArray,aSize);
	
	
	cout<<"******** selection sort **********"<<endl;
	selectionSort(strArray,aSize);
	printAr(strArray,aSize);
	cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl;
	copyArray(orgArray,strArray,aSize);
	
	cout<<"******** insert sort **********"<<endl;
	insertSort(strArray,aSize);
	printAr(strArray,aSize);
	cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl;
	copyArray(orgArray,strArray,aSize);
	
	cout<<"******** Bubble sort **********"<<endl;
	BubbleSort(strArray,aSize);
	printAr(strArray,aSize);
	cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl;
	return 0;
}
Esempio n. 6
0
int main(void)
{
    int length = 0, height = 0, i, k, lowVal = -1000, highVal = -1000;
    char entred[100] = "";

    do{
        drawField(COLS/4, ROWS/4, COLS/2, ROWS/2);
        k = setText(COLS/4 + 2, 3*ROWS/8, "Enter matrix length [1..9]\n& height [1..9]\nparting values with coma:", FIELD_COLOR);
        getText(COLS/4 + 2, 3*ROWS/8 + k + 1, entred, FIELD_BACKGROUND, FORE_BLACK);
        getPartiedInts(entred, &length, &height);
        if((length > 9 || length < 1) || (height > 9 || height< 1)){
            setTextLine(COLS/4 + 2, 3*ROWS/8 + k + 4, "Invalid input!", FIELD_BACKGROUND | FOREGROUND_RED);
            Sleep(1500);
        }
    }while((length > 9 || length < 1) || (height > 9 || height< 1));

    do{
        drawField(COLS/4, ROWS/4, COLS/2, ROWS/2);
        k = setText(COLS/4 + 2, 3*ROWS/8, "Enter matrix random values diapason\nparting left & right bounds with coma:", FIELD_COLOR);
        getText(COLS/4 + 2, 3*ROWS/8 + k + 1, entred, FIELD_BACKGROUND, FORE_BLACK);
        getPartiedInts(entred, &lowVal, &highVal);
        if((lowVal > highVal) || (highVal > 999) || (lowVal < -999)){
            setTextLine(COLS/4 + 2, 3*ROWS/8 + k + 4, "Invalid input!", FIELD_BACKGROUND | FOREGROUND_RED);
            Sleep(1500);
        }
    }while((lowVal > highVal) || (highVal > 999) || (lowVal < -999));


    int matr[height][length], mcpy[length][height], isTurned = 0, toSwitch = 0, firstToSwap, secondToSwap;
    int cX, cY, val, row;
    fillRand(length, height, matr, lowVal, highVal);

    int y = 2 + height*2;

    short color = FIELD_COLOR, toClean = 0, isSwaped = 0, help = 0, toPickOutCols = 0, toYellow = 0, toPickOutRow = 0;
    char * g, cpy[100];
    COORD swaped[2];
    clearScr();
    drawField(0, 0, COLS - 1, y);

    while(1){
        y = isTurned ? (2 + length*2) : (2 + height*2);
        if(toClean){
            toClean = 0;
            clean(y);
        }
        printMatr(length, height, matr, isTurned, toSwitch, color);
        color = FIELD_COLOR;

        if(isSwaped){
            pickOut(length, height, matr, isTurned, swaped[0], BACKGROUND_GREEN);
            pickOut(length, height, matr, isTurned, swaped[1], BACKGROUND_RED);
            isSwaped = 0;
        } else if(toYellow){
            printEl(length, height, matr, isTurned, cX - 1, cY - 1, FORE_YELLOW | FIELD_BACKGROUND | FOREGROUND_INTENSITY);
            toYellow = 0;
        } else if(toPickOutRow){
            pickOutRow(length, height, matr, isTurned, row - 1, BACKGROUND_GREEN);
            toPickOutRow = 0;
        } else if(toPickOutCols){
            pickOutCol(length, height, matr, isTurned, firstToSwap - 1, BACKGROUND_GREEN);
            pickOutCol(length, height, matr, isTurned, secondToSwap - 1, BACKGROUND_RED);
            toPickOutCols = 0;
        }

        toSwitch = 0;
        setTextLine(1, y + 2, "Enter your command:",  FORE_WHITE);
        do{
            getText(1, y + 3, entred, BACK_BLACK, FOREGROUND_GREEN);
        }while(entred[0] == '\0');

        strcpy(cpy, entred);
        g = strtok(cpy, " ");
        if(!g)
            g = "\n";
        for(i = 2; i < COLS; i++){
            moveCursor(i, y + 3);
            putchar(' ');
        }
        if(!strcmp(entred, "help")){
            helpComm(y + 5);
            help = 1;
        }else if(!strcmp(entred, "clear all")){
            clearMatr(length, height, matr);
            color = FIELD_BACKGROUND | FORE_YELLOW | FOREGROUND_INTENSITY;
        }else if(!strcmp(g, "random")){
            lowVal = -1000;
            highVal = -1000;
            char cpy1[100];
            for(i = 0; cpy[i + 7] != '\0'; i++){
                cpy1[i] = cpy[i + 7];
            }
            cpy1[i] = '\0';
            getPartiedInts(cpy1, &lowVal, &highVal);

            if((lowVal > highVal) || (highVal > 999) || (lowVal < -999)){
                invalidInput(y);
            }else{
                fillRand(length, height, matr, lowVal, highVal);
                color = FIELD_BACKGROUND | FORE_YELLOW | FOREGROUND_INTENSITY;
            }
        }else if(!strcmp(g, "set")){
            cX = -1;
            cY = -1;
            val = -1000;
            char cpy1[100], *l;
            for(i = 0; cpy[i + 4] != '\0'; i++){
                cpy1[i] = cpy[i + 4];
            }
            cpy1[i] = '\0';
            getPartiedInts(cpy1, &cX, &cY);
            l = strtok(cpy1, ":");
            l = strtok(NULL, ":");
            if(l != NULL){
                val = atoi(l);
            }

            if(!isTurned){
                if(cX > length || cX <= 0 || cY > height || cY <= 0 || val > 999 || val < -999){
                    invalidInput(y);
                }else{
                    matr[cY -  1][cX - 1] = val;
                    toYellow = 1;
                }
            }else{
                if(cX > height || cX <= 0 || cY > length || cY <= 0 || val > 999 || val < -999){
                    invalidInput(y);
                }else{
                    matr[cX - 1][cY - 1] = val;
                    toYellow = 1;
                }
            }
        }else if(!strcmp(entred, "print upright")){
            isTurned = !isTurned;
            toSwitch = 1;
        }else if(!strcmp(entred, "middle value")){
            double mid = countMiddle(length, height, matr);
            setTextColor(FORE_WHITE);
            moveCursor(5, y + 4);
            printf("middle value: ");
            setTextColor(FORE_YELLOW);
            moveCursor(22, y + 4);
            printf("%f                         ", mid);
            help = 1;
        }else if(!strcmp(g, "sum")){
            int sum;
            row = -1;
            g = strtok(NULL, " ");
            if(g != NULL && !strcmp(g, "in")){
                g = strtok(NULL, " ");
                if(g != NULL && !strcmp(g, "row")){
                    g = strtok(NULL, " ");
                    if(g != NULL)
                        row = atoi(g);
                }
            }
            if(row < 0 || row > (isTurned ? length : height))
                invalidInput(y);
            else{
                sum = sumInRow(length, height, matr, isTurned, row -1);
                toPickOutRow = 1;
                setTextColor(FORE_WHITE);
                moveCursor(5, y + 4);
                printf("sum in %dth row: ", row);
                setTextColor(FORE_YELLOW);
                moveCursor(22, y + 4);
                printf("%d                         ", sum);
                help = 1;
            }
        }else if(!strcmp(entred, "swap 1")){
            swapMinMax(length, height, matr, isTurned, 1, swaped);
            isSwaped = 1;
        }else if(!strcmp(entred, "swap 2")){
            swapMinMax(length, height, matr, isTurned, 0, swaped);
            isSwaped = 1;
        }else if(!strcmp(entred, "swap cols")){
            swapCols(length, height, matr, isTurned, &firstToSwap, &secondToSwap);
            toPickOutCols = 1;
        }else if(!strcmp(entred, "clean workspace") && help){
            toClean = 1;
            help = 0;
        }else if(!strcmp(entred, "f**k you")){
            clearScr();
            setTextLine(0, 0, "GO F**K YOURSELF!", FOREGROUND_RED | FOREGROUND_INTENSITY);
            setTextColor(FORE_WHITE);
            return EXIT_FAILURE;
        }else if(!strcmp(entred, "exit")){
            clearScr();
            setTextColor(FORE_WHITE);
            return EXIT_SUCCESS;
        }else{
            invalidInput(y);
        }
    }
    return EXIT_SUCCESS;
}