This commit is contained in:
Damián Korpesio 2021-12-28 16:21:01 +01:00
parent b884843e8e
commit 234c9e35b6
13 changed files with 167 additions and 17 deletions

BIN
OS/server Normal file

Binary file not shown.

63
OS/server.c Normal file
View File

@ -0,0 +1,63 @@
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#define LINESIZE 128
void error(char *msg){
perror(msg);
exit(1);
}
int main (int argc, char *argv[]){
int sockfd;
int newsockfd;
int portno;
int clilen;
int n;
char buffer[LINESIZE];
struct sockaddr_in serv_addr;
struct sockaddr_in cli_addr;
if (argc < 2){
fprintf(stderr, "ERROR, no port provided\n");
exit(1);
}
sockfd = socket(PF_INET, SOCK_STREAM, 0);
if (sockfd < 0){
error("ERROR opening socket");
}
bzero((char *)&serv_addr, sizeof(serv_addr));
portno = atoi(argv[1]);
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno);
printf("Server is waiting for the message, please wait...\n");
if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof (serv_addr)) < 0){
error("ERROR on binding");
}
listen(sockfd, 5);
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
if (newsockfd < 0){
error("ERROR on accept");
}
bzero(buffer, LINESIZE);
n = read(newsockfd, buffer, LINESIZE);
if (n < 0){
error("ERROR reading from socket");
}
printf("The message is: %s", buffer);
fprintf(stderr, "The mesaage contains %d bytes.\n", n);
close(sockfd);
return 0;
}

BIN
a2/program Normal file

Binary file not shown.

BIN
a4/program Normal file

Binary file not shown.

View File

@ -2,8 +2,8 @@
#include<stdlib.h>
#define LINESIZE 100
struct heap {
int* array;
int size;
int* line;
int capacity;
};
@ -21,7 +21,7 @@ int pravy_syn(int i){
struct heap* create_heap(int capacity){
struct heap* h = calloc(1,sizeof(struct heap));
h->array = calloc(capacity,sizeof(int));
h->line = calloc(capacity,sizeof(int));
h->capacity =capacity;
h->size = 0;
return h;
@ -37,7 +37,7 @@ void check_heap_property(struct heap* h){
break;
}
if(h->array[i] > h->array[pravy] || h->array[i] > h->array[lavy]){
if(h->line[i] > h->line[pravy] || h->line[i] > h->line[lavy]){
printf("%s\n","Niejekopa.");
exit(0);
}
@ -46,15 +46,15 @@ void check_heap_property(struct heap* h){
}
void delete_heap(struct heap* h){
free(h->array);
free(h->line);
free(h);
}
void swap(int arr[],int a, int b){
int temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
//void vymen(int arr[],int a, int b){
// int pom = arr[a];
// arr[a] = arr[b];
// arr[b] = pom;
//}
void add(struct heap* h,int value){
@ -64,7 +64,7 @@ void add(struct heap* h,int value){
}
h->size += 1;
h->array[i] = value;
h->line[i] = value;
}
@ -79,7 +79,7 @@ void print(struct heap* h,int count_spaces,int index){
for(int i =0;i<count_spaces;i++){
printf(" ");
}
printf("%d\n",h->array[index]);
printf("%d\n",h->line[index]);
print(h,count_spaces+1,lavy_syn(index));
print(h,count_spaces+1,pravy_syn(index));
@ -91,24 +91,28 @@ void sort(struct heap *h){
int i = h->size-1;
int p = parent(i);
while(h->array[i] < h->array[p]) {
swap(h->array,i, p);
while(h->line[i] < h->line[p]) {
int arr[] = h->line;
int pom = arr[i];
arr[i] = arr[p];
arr[p] = pom;
//vymen(h->line,i, p);
i = parent(i);
}
}
int main(){
int i = 0;
int temp_array[LINESIZE] = {0};
int temp_line[LINESIZE] = {0};
while(scanf("%d",&temp_array[i]) == 1) {
while(scanf("%d",&temp_line[i])== 1) {
i++;
}
struct heap* h = create_heap(i);
for(int j =0;j<i;j++){
add(h,temp_array[j]);
add(h,temp_line[j]);
}
check_heap_property(h);

BIN
cv8/program Normal file

Binary file not shown.

14
sk1a/Makefile Normal file
View File

@ -0,0 +1,14 @@
all: program
maze.o: maze.c
gcc -c -g -Wall maze.c -o maze.o
main.o: main.c
gcc -c -g -Wall main.c -o main.o
program: maze.o main.o
gcc -g -Wall maze.o main.o -o program
clean:
rm program
rm *.o

39
sk1a/main.c Normal file
View File

@ -0,0 +1,39 @@
#define SZ 5
#include <stdio.h>
#include <string.h>
#include "maze.h"
void print_solution(char* matrix,int sz){
for (int i = 0; i < sz * sz; i++){
printf("%c ",matrix[i]);
if (i % sz == (sz-1)){
printf("\n");
}
}
}
int main(){
char tmaze[SZ+1][SZ+1]={
"*x ",
" x ",
" x ",
" x ",
" ",
};
char maze[SZ*SZ];
memset(maze,' ',SZ*SZ);
for (int i= 0; i < SZ; i++){
for (int j= 0; j < SZ; j++){
if (tmaze[i][j] == 'x'){
maze[i*SZ+j] = 'x';
}
}
}
int r = solve_maze(maze,SZ);
if (!r){
printf("Nenasiel som riesenie\n");
}
print_solution(maze,SZ);
return 0;
}

BIN
sk1a/main.o Normal file

Binary file not shown.

8
sk1a/maze.c Normal file
View File

@ -0,0 +1,8 @@
#include <stdio.h>
#include <string.h>
#include "maze.h"
#include <assert.h>
int solve_maze(char* maze,int size){
return 0;
}

22
sk1a/maze.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef _MAZEH
#define _MAZEH
/**
* Funkcia by mala zobrať vstupnú mriežku a
* vyznačiť na nej cestu z ľavého horného rohu do pravého dolného rohu.
* Mriežka je uložená do jednorozmerného poľa, pričom najprv ide prvý riadok,
* za ním druhý a tak ďalej.
*
* Na mriežke sa nachádzajú znaky:
* ' ' - voľné miesto
* 'x' - stena. Stena nesmie byť prepísaná.
* '*' - poloha potkana. Na začiatku je na 0,0.
*
* @param maze Štvorcová mriežka rozmeru size x size.
* @param size Rozmer mriežky
* @return 1 ak existuje riešenie, 0 inak.
*/
int solve_maze(char* maze,int size);
#endif

BIN
sk1a/maze.o Normal file

Binary file not shown.

BIN
sk1a/program Normal file

Binary file not shown.