Compare commits
No commits in common. "main" and "e8b026f34f05919affadef13be17176b6bb53170" have entirely different histories.
main
...
e8b026f34f
116
du1/program.c
116
du1/program.c
@ -1,116 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define LINESIZE 100
|
||||
#define MAX_ITEMS 100
|
||||
|
||||
struct pizza {
|
||||
float prize;
|
||||
char name[LINESIZE];
|
||||
};
|
||||
|
||||
char hacker_script(char c) {
|
||||
if (isupper(c)) {
|
||||
return tolower(c);
|
||||
}
|
||||
|
||||
char numbers[] = "0123456789";
|
||||
char letters[] = "oizeasbtbq";
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (c == numbers[i]) {
|
||||
return letters[i];
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int search_string(const char* heap, const char* needle) {
|
||||
int heap_len = strlen(heap);
|
||||
int needle_len = strlen(needle);
|
||||
|
||||
if (needle_len > heap_len) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i <= heap_len - needle_len; i++) {
|
||||
int found = 1;
|
||||
|
||||
for (int j = 0; j < needle_len; j++) {
|
||||
char h_char = hacker_script(heap[i + j]);
|
||||
char n_char = hacker_script(needle[j]);
|
||||
|
||||
if (h_char != n_char) {
|
||||
found = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int read_pizza(struct pizza* item, FILE* stream) {
|
||||
char line[LINESIZE];
|
||||
char price_line[LINESIZE];
|
||||
|
||||
if (fgets(line, LINESIZE, stream) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
line[strcspn(line, "\n")] = 0;
|
||||
|
||||
if (fgets(price_line, LINESIZE, stream) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* endptr;
|
||||
float value = strtof(price_line, &endptr);
|
||||
|
||||
if (endptr == price_line || value == 0.0f) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy(item->name, line);
|
||||
item->prize = value;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char search_term[LINESIZE];
|
||||
struct pizza items[MAX_ITEMS];
|
||||
int item_count = 0;
|
||||
|
||||
printf("Zadaj hladanu surovinu:\n");
|
||||
if (fgets(search_term, LINESIZE, stdin) == NULL) {
|
||||
printf("Chyba pri čítaní hľadaného reťazca\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
search_term[strcspn(search_term, "\n")] = 0;
|
||||
|
||||
printf("Zadaj jedalny listok:\n");
|
||||
|
||||
while (item_count < MAX_ITEMS && read_pizza(&items[item_count], stdin)) {
|
||||
item_count++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < item_count; i++) {
|
||||
if (search_string(items[i].name, search_term) != -1) {
|
||||
printf("%s\n", items[i].name);
|
||||
printf("%.2f\n", items[i].prize);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Nacitanych %d poloziek.\n", item_count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1,55 +1,52 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define MAX_PIZZ 1000
|
||||
#define MAX_NAZOV 101
|
||||
#define MAX 1000
|
||||
#define SIZE 101
|
||||
|
||||
typedef struct {
|
||||
char nazov[MAX_NAZOV];
|
||||
double cena;
|
||||
} Pizza;
|
||||
|
||||
int porovnaj(const void *a, const void *b) {
|
||||
const Pizza *p1 = (const Pizza *)a;
|
||||
const Pizza *p2 = (const Pizza *)b;
|
||||
|
||||
if (p1->cena < p2->cena) return -1;
|
||||
if (p1->cena > p2->cena) return 1;
|
||||
|
||||
return strcasecmp(p1->nazov, p2->nazov);
|
||||
}
|
||||
struct pizza {
|
||||
char name[SIZE];
|
||||
float price;
|
||||
};
|
||||
|
||||
int main() {
|
||||
Pizza zoznam[MAX_PIZZ];
|
||||
int n = 0;
|
||||
struct pizza list[MAX];
|
||||
int count = 0;
|
||||
|
||||
char name[SIZE];
|
||||
char price_str[SIZE];
|
||||
float price;
|
||||
|
||||
while (1) {
|
||||
if (!fgets(zoznam[n].nazov, MAX_NAZOV, stdin))
|
||||
break;
|
||||
if (fgets(name, SIZE, stdin) == NULL) break;
|
||||
name[strcspn(name, "\n")] = 0;
|
||||
if (strlen(name) == 0) break;
|
||||
if (fgets(price_str, SIZE, stdin) == NULL) break;
|
||||
price_str[strcspn(price_str, "\n")] = 0;
|
||||
if (sscanf(price_str, "%f", &price) != 1) break;
|
||||
if (price <= 0) break;
|
||||
|
||||
zoznam[n].nazov[strcspn(zoznam[n].nazov, "\n")] = '\0';
|
||||
|
||||
if (strlen(zoznam[n].nazov) == 0)
|
||||
break;
|
||||
|
||||
char riadok[50];
|
||||
if (!fgets(riadok, sizeof(riadok), stdin))
|
||||
break;
|
||||
|
||||
if (sscanf(riadok, "%lf", &zoznam[n].cena) != 1)
|
||||
break;
|
||||
|
||||
n++;
|
||||
if (n >= MAX_PIZZ) break;
|
||||
strcpy(list[count].name, name);
|
||||
list[count].price = price;
|
||||
count++;
|
||||
if (count >= MAX) break;
|
||||
}
|
||||
|
||||
qsort(zoznam, n, sizeof(Pizza), porovnaj);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
printf("%s\n%.6f\n", zoznam[i].nazov, zoznam[i].cena);
|
||||
for (int i = 0; i < count - 1; i++) {
|
||||
for (int j = 0; j < count - i - 1; j++) {
|
||||
if (list[j].price > list[j + 1].price ||
|
||||
(list[j].price == list[j + 1].price && strcmp(list[j].name, list[j + 1].name) > 0)) {
|
||||
struct pizza temp = list[j];
|
||||
list[j] = list[j + 1];
|
||||
list[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < count; i++) {
|
||||
printf("%s\n%.6f\n", list[i].name, list[i].price);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define STACK_SIZE 10
|
||||
|
||||
@ -9,75 +9,21 @@ struct stack {
|
||||
int size;
|
||||
};
|
||||
|
||||
void print_stack(struct stack *s) {
|
||||
for (int i = 0; i < s->size; i++) {
|
||||
printf("%.2f ", s->values[i]);
|
||||
}
|
||||
printf("\n");
|
||||
void push_stack(float value, struck stack *s){
|
||||
if (s->size >=STACK_SIZE){
|
||||
printf("Zapsinik je plny\n")
|
||||
exit (1);
|
||||
}
|
||||
|
||||
void push_stack(struct stack *s, float value) {
|
||||
if (s->size >= STACK_SIZE) {
|
||||
printf("full stack\n");
|
||||
exit(0);
|
||||
}
|
||||
s->values[s->size] = value;
|
||||
s->size++;
|
||||
s->values[s->size] = value;
|
||||
s->size++;
|
||||
}
|
||||
|
||||
float pop_stack(struct stack *s) {
|
||||
if (s->size <= 0) {
|
||||
printf("no input\n");
|
||||
exit(0);
|
||||
if (s->size <= 0){
|
||||
printf("zasobnik je prazdny \n");
|
||||
exit(1);
|
||||
}
|
||||
s->size--;
|
||||
return s->values[s->size];
|
||||
}
|
||||
|
||||
int main() {
|
||||
struct stack s;
|
||||
s.size = 0;
|
||||
|
||||
char input[100];
|
||||
|
||||
while (scanf("%s", input) == 1) {
|
||||
if (strcmp(input, "+") == 0 || strcmp(input, "-") == 0 ||
|
||||
strcmp(input, "*") == 0 || strcmp(input, "/") == 0) {
|
||||
|
||||
if (s.size < 2) {
|
||||
printf("not enough operands\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
float b = pop_stack(&s);
|
||||
float a = pop_stack(&s);
|
||||
float result;
|
||||
|
||||
if (strcmp(input, "/") == 0 && b == 0) {
|
||||
printf("division by zero\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (strcmp(input, "+") == 0) result = a + b;
|
||||
else if (strcmp(input, "-") == 0) result = a - b;
|
||||
else if (strcmp(input, "*") == 0) result = a * b;
|
||||
else result = a / b;
|
||||
|
||||
push_stack(&s, result);
|
||||
print_stack(&s);
|
||||
}
|
||||
else {
|
||||
char *endptr;
|
||||
float val = strtof(input, &endptr);
|
||||
if (*endptr != '\0') {
|
||||
printf("bad input\n");
|
||||
exit(0);
|
||||
}
|
||||
push_stack(&s, val);
|
||||
print_stack(&s);
|
||||
}
|
||||
}
|
||||
|
||||
printf("no input\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
13
du4/Makefile
Normal file
13
du4/Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
CFLAGS= -std=c99 -g -Wall
|
||||
|
||||
all: train
|
||||
|
||||
%.o: %.c
|
||||
gcc -c -o $@ $< $(CFLAGS)
|
||||
|
||||
train: main.o a_train.o
|
||||
gcc main.o a_train.o -o train
|
||||
|
||||
clean:
|
||||
rm *.o train
|
||||
|
||||
18
du4/a_train.c
Normal file
18
du4/a_train.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include "a_train.h"
|
||||
#include <stdio.h>
|
||||
|
||||
struct car* add_car(struct car* first,const char* target) {
|
||||
return NULL;
|
||||
}
|
||||
dddddddd
|
||||
void print_train(struct car* first) {
|
||||
}
|
||||
|
||||
void cancel_train(struct car* first) {
|
||||
}
|
||||
|
||||
|
||||
struct car* clear_train(struct car* first, const char* target) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
51
du4/a_train.h
Normal file
51
du4/a_train.h
Normal file
@ -0,0 +1,51 @@
|
||||
#ifndef TRAIN_H
|
||||
#define TRAIN_H
|
||||
#define SIZE 100
|
||||
|
||||
/**
|
||||
* Jeden vozen vlaku
|
||||
*/
|
||||
struct car {
|
||||
/**
|
||||
* Nazov cielovej stanice
|
||||
*/
|
||||
char value[SIZE];
|
||||
/**
|
||||
* Smenik na dalsi vozen
|
||||
*/
|
||||
struct car* next;
|
||||
};
|
||||
|
||||
/**
|
||||
* Prida vozen na koniec vlaku.
|
||||
*
|
||||
* @arg nazov cielovej stanice, ktory sa ma priradit novemu voznu.
|
||||
* @return smernik na zaciatok vlaku.
|
||||
*/
|
||||
struct car* add_car(struct car* first,const char* target);
|
||||
|
||||
|
||||
/**
|
||||
* Vypise vsetky vozne vo vlaku
|
||||
*
|
||||
* @arg smernik na prvy vozen
|
||||
*/
|
||||
void print_train(struct car* first);
|
||||
|
||||
/**
|
||||
* Zrusenie vsetkych voznov vo vlaku.
|
||||
* @arg smernik na prvy vozen
|
||||
*/
|
||||
void cancel_train(struct car* first);
|
||||
|
||||
/**
|
||||
* Vyradenie vsetkych voznov, ktorych cielova stanica je target
|
||||
*
|
||||
* @arg smernik na prvy vozen
|
||||
* @arg cielova stanica, ktora sa ma vyradit z vlaku.
|
||||
* @return smernik na novy prvy vozen
|
||||
*
|
||||
*/
|
||||
struct car* clear_train(struct car* first,const char* target);
|
||||
|
||||
#endif // TRAIN_H
|
||||
17
du4/main.c
Normal file
17
du4/main.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include "a_train.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// Testovaci subor pre vlak
|
||||
int main(){
|
||||
struct car* train = NULL;
|
||||
train = add_car(train,"Presov");
|
||||
train = add_car(train,"Bratislava");
|
||||
train = add_car(train,"Levoca");
|
||||
train = add_car(train,"Spiska Nova Ves");
|
||||
print_train(train);
|
||||
clear_train(train,"Levoca");
|
||||
print_train(train);
|
||||
cancel_train(train);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user