Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Complete some missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
kvetinac97 committed Jul 9, 2021
1 parent 1afd1ff commit f84ee33
Show file tree
Hide file tree
Showing 34 changed files with 3,733 additions and 2 deletions.
4 changes: 2 additions & 2 deletions BI-CAO/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Got *all the points and bonuses*, resulting in *130 %* (65/50 points) and grade

== Tests

First test, written on 3rd, 7th and 11th lab. +
I did not archive second and third test.
First and third test (written on 3rd, 11th lab).
I did not archive second test (7th lab), as it was written on paper.

== Notes

Expand Down
2,287 changes: 2,287 additions & 0 deletions BI-CAO/tests/B1-T3-PA-0915_wrzecond.nb

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 49 additions & 0 deletions BI-PA1/labs/07_program/hash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include<stdio.h>
#include<string.h>

#define TEXT_MAX 128

//Hashovací funkce djb2 (http://www.cse.yorku.ca/~oz/hash.html)
long hash(char *str) {

long hash = 5381;
int c;

while ((c = *str++))
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */

return hash;

}

void nactiRetezec(char* retezec){

fgets(retezec, TEXT_MAX, stdin);
int delka = strlen(retezec);

if (retezec[delka - 1] == '\n')
retezec[delka - 1] = '\0';
else
printf("\n");

}

int main(void){

char retezec1[TEXT_MAX];
char retezec2[TEXT_MAX];

printf("Zadejte textovy retezec 1:\n");
nactiRetezec(retezec1);

printf("Zadejte textovy retezec 2:\n");
nactiRetezec(retezec2);

long hash1 = hash(retezec1);
long hash2 = hash(retezec2);

printf((hash1 == hash2) ? "Otisky retezcu jsou stejne.\n" : "Otisky retezcu se lisi.\n");

return 0;
}

48 changes: 48 additions & 0 deletions BI-PA1/labs/07_program/strtoupper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include<stdio.h>
#include<string.h>

#define TEXT_MAX 128

//Předám si odkaz na první znak řetězce
void strtoupper(char * retezec) {

//Dokud se nejedná o nulový znak (konec řetězce)
while (*retezec != '\0') {

//Pokud je to znak malého písmena, převedu ho na velké
if (*retezec >= 97 && *retezec <= 122)
*retezec = (*retezec - 32);

//Posunu se v řetězci
retezec++;

}

}

void nactiRetezec(char* retezec){

fgets(retezec, TEXT_MAX, stdin);
int delka = strlen(retezec);

if (retezec[delka - 1] == '\n')
retezec[delka - 1] = '\0';
else
printf("\n");

}

int main(void){

char retezec[TEXT_MAX];
printf("Zadejte textovy retezec:\n");

nactiRetezec(retezec);

//Samotné převedení a vypsání převedeného řetězce
strtoupper(retezec);
printf("%s\n", retezec);

return 0;
}

104 changes: 104 additions & 0 deletions BI-PA1/labs/08_program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define MODRY_HRAC 1
#define ORANZOVY_HRAC -1
#define NEOBSAZENO 0

/* Funkce vrací 0, pokud je požadovaný tah neplatný. */
int tah( int hraciDeska[5][5], int hrac, int radek, char sloupec, int cilovyRadek, char cilovySloupec ) {

if (radek < 1 || radek > 5 || cilovyRadek < 1 || cilovyRadek > 5)
return 0;

sloupec = tolower(sloupec);
cilovySloupec = tolower(cilovySloupec);

if (sloupec < 'a' || sloupec > 'e' || cilovySloupec < 'a' || cilovySloupec > 'e')
return 0;

if (hraciDeska[radek-1][sloupec-97] != hrac)
return 0;

if (hraciDeska[cilovyRadek-1][cilovySloupec-97] != 0)
return 0;

if (abs(cilovyRadek-radek) != 1 || abs(cilovySloupec-sloupec) != 1)
return 0;

hraciDeska[cilovyRadek-1][cilovySloupec-97] = hraciDeska[radek-1][sloupec-97];
hraciDeska[radek-1][sloupec-97] = 0;
return 1;

}

void vytiskniDesku(int hraciDeska[5][5]){
printf(" A B C D E\n");
for (int i = 0; i < 5; i++) {
printf("%d ", i+1);
for (int j = 0; j < 5; j++)
printf("%c ", hraciDeska[i][j] == 1 ? 'M' : (hraciDeska[i][j] == -1 ? 'R' : 'O'));
printf("\n");
}
}

int main( void ) {
int hraciDeska[5][5] = {0};
int aktualniHrac = MODRY_HRAC,
vysledekNacteni,
radek,
cilovyRadek;
char sloupec,
cilovySloupec;

for (int i = 0; i < 5; i++)
hraciDeska[0][i] = 1;

for (int i = 0; i < 5; i++)
hraciDeska[4][i] = -1;

vytiskniDesku(hraciDeska);

while ( 1 ) {
printf( "Na rade je %s hrac. Zadejte pocatecni cislo radku a pismeno sloupce a take cilove cislo radku a pismeno sloupce:\n",
aktualniHrac == MODRY_HRAC ? "modry" : "oranzovy" );

vysledekNacteni = scanf( "%d %c %d %c", &radek, &sloupec, &cilovyRadek, &cilovySloupec );
if ( vysledekNacteni == EOF ) {
printf( "Ukoncili jste hru.\n" );
return 0;
}

if ( vysledekNacteni != 4 || tah( hraciDeska, aktualniHrac, radek, sloupec, cilovyRadek, cilovySloupec ) != 1 ) {
printf( "Neplatny vstup. Zkuste to znovu.\n" );
char c = 0;
do {
c = fgetc(stdin);
}
while (c != EOF && c != '\n');
continue;
}

int vyhralModry = 1, vyhralCerveny = 1;
for (int i = 0; i < 5; i++)
if (hraciDeska[0][i] != -1)
vyhralCerveny = 0;

for (int i = 0; i < 5; i++)
if (hraciDeska[4][i] != 1)
vyhralModry = 0;

if (vyhralModry || vyhralCerveny)
break;

/* Výhodné mít hodnoty '1' a '-1'. */
aktualniHrac *= -1;

vytiskniDesku(hraciDeska);
}

printf("Vyhral %s.\n", aktualniHrac == MODRY_HRAC ? "modry" : "oranzovy");

return 0;
}
82 changes: 82 additions & 0 deletions BI-PA1/labs/09_program/maze.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include <stdio.h>
#include <stdlib.h>

#define INIT_SIZE 4

/* Input-output argument "maze"
Returns 0 if bad input occurs,
returns EOF if EOF occurs,
returns size of the row. */
int readMazeRow ( char ** maze, int * size, int * maxSize ) {
char element;
int rowSize = 0;

while ( scanf ( &( ( *maze )[*size] ) ) != EOF ) { // *(char **) -> char *, *(int *) -> int
element = ( *maze )[*size];

rowSize++;
(*size)++;

if ( element == '\n' )
break;

if ( element != 'Z' && element != 'T' && element != 'H' ) {
return 0;
}

/* Realloc */
if ( *size == *maxSize ) {
/* Enough memory assumption */
*maxSize *= 2;
*maze = ( char * ) realloc ( *maze, *maxSize * sizeof ( char ) );
}
}

return rowSize;
}

char * readMaze ( int * rowSize, int * rows ) {
char * maze = ( char * ) malloc ( INIT_SIZE * sizeof ( char ) );
int maxSize = INIT_SIZE,
size = 0,
firstRowSize,
secondRowSize;

*rows = 0;

/* Read first row */
if ( ( firstRowSize = readMazeRow ( &maze, &size, &maxSize ) ) == 0 ) {
free ( maze );
return NULL;
}

*rows = 1;
while ( ( secondRowSize = readMazeRow ( &maze, &size, &maxSize ) ) != EOF ) {
if ( secondRowSize == 0 || firstRowSize != secondRowSize ) {
free ( maze );
return NULL;
}

(*rows)++;
}

*rowSize = firstRowSize;
return maze;
}

int main( void ){
char * maze;
int rowSize,
rows;

printf ( "Zadej bludiste:\n" );
if ( ( maze = readMaze ( &rowSize, &rows ) ) == NULL){
printf("Nespravny vstup.\n");
return 1;
}

/* Prochazeni bludiste */

free ( maze );
return 0;
}
Loading

0 comments on commit f84ee33

Please sign in to comment.