Compare commits
No commits in common. "e8b026f34f05919affadef13be17176b6bb53170" and "main" have entirely different histories.
e8b026f34f
...
main
116
du1/program.c
Normal file
116
du1/program.c
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
#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,52 +1,55 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#define MAX 1000
|
#define MAX_PIZZ 1000
|
||||||
#define SIZE 101
|
#define MAX_NAZOV 101
|
||||||
|
|
||||||
struct pizza {
|
typedef struct {
|
||||||
char name[SIZE];
|
char nazov[MAX_NAZOV];
|
||||||
float price;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
struct pizza list[MAX];
|
Pizza zoznam[MAX_PIZZ];
|
||||||
int count = 0;
|
int n = 0;
|
||||||
|
|
||||||
char name[SIZE];
|
|
||||||
char price_str[SIZE];
|
|
||||||
float price;
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (fgets(name, SIZE, stdin) == NULL) break;
|
if (!fgets(zoznam[n].nazov, MAX_NAZOV, stdin))
|
||||||
name[strcspn(name, "\n")] = 0;
|
break;
|
||||||
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;
|
|
||||||
|
|
||||||
strcpy(list[count].name, name);
|
zoznam[n].nazov[strcspn(zoznam[n].nazov, "\n")] = '\0';
|
||||||
list[count].price = price;
|
|
||||||
count++;
|
if (strlen(zoznam[n].nazov) == 0)
|
||||||
if (count >= MAX) break;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < count - 1; i++) {
|
qsort(zoznam, n, sizeof(Pizza), porovnaj);
|
||||||
for (int j = 0; j < count - i - 1; j++) {
|
|
||||||
if (list[j].price > list[j + 1].price ||
|
for (int i = 0; i < n; i++) {
|
||||||
(list[j].price == list[j + 1].price && strcmp(list[j].name, list[j + 1].name) > 0)) {
|
printf("%s\n%.6f\n", zoznam[i].nazov, zoznam[i].cena);
|
||||||
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define STACK_SIZE 10
|
#define STACK_SIZE 10
|
||||||
|
|
||||||
@ -9,21 +9,75 @@ struct stack {
|
|||||||
int size;
|
int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
void push_stack(float value, struck stack *s){
|
void print_stack(struct stack *s) {
|
||||||
if (s->size >=STACK_SIZE){
|
for (int i = 0; i < s->size; i++) {
|
||||||
printf("Zapsinik je plny\n")
|
printf("%.2f ", s->values[i]);
|
||||||
exit (1);
|
}
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
s->values[s->size] = value;
|
|
||||||
s->size++;
|
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++;
|
||||||
}
|
}
|
||||||
|
|
||||||
float pop_stack(struct stack *s) {
|
float pop_stack(struct stack *s) {
|
||||||
if (s->size <= 0){
|
if (s->size <= 0) {
|
||||||
printf("zasobnik je prazdny \n");
|
printf("no input\n");
|
||||||
exit(1);
|
exit(0);
|
||||||
}
|
}
|
||||||
s->size--;
|
s->size--;
|
||||||
return s->values[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
13
du4/Makefile
@ -1,13 +0,0 @@
|
|||||||
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
|
|
||||||
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,51 +0,0 @@
|
|||||||
#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
17
du4/main.c
@ -1,17 +0,0 @@
|
|||||||
#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