This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1afd1ff
commit f84ee33
Showing
34 changed files
with
3,733 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.