cv2
This commit is contained in:
parent
652172aacc
commit
86cad03297
BIN
cv2/program
BIN
cv2/program
Binary file not shown.
@ -1,88 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define LINE_SIZE 100
|
||||
#define POCET 100
|
||||
|
||||
struct pizza {
|
||||
float price;
|
||||
char name[LINE_SIZE];
|
||||
};
|
||||
|
||||
void delet(char* str) {
|
||||
int i = 0;
|
||||
|
||||
while (str[i] != '\n' && str[i] != 0) {
|
||||
i++;
|
||||
}
|
||||
str[i] = 0;
|
||||
}
|
||||
|
||||
int read_pizza(struct pizza* item) {
|
||||
|
||||
char line[LINE_SIZE];
|
||||
memset(line, 0, LINE_SIZE);
|
||||
|
||||
char* r = fgets(line, LINE_SIZE, stdin);
|
||||
delet(line);
|
||||
|
||||
if (r != NULL && line[1] != 0) {
|
||||
|
||||
char line2[LINE_SIZE];
|
||||
|
||||
memset(line2, 0, LINE_SIZE);
|
||||
fgets(line2, LINE_SIZE, stdin);
|
||||
|
||||
float value = strtof(line2, NULL);
|
||||
|
||||
if (value == 0.0F) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
item->price = value;
|
||||
strcpy(item->name, line);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int compare_pizza(const void* a, const void* b) {
|
||||
const struct pizza* pizza_a = (const struct pizza*)a;
|
||||
const struct pizza* pizza_b = (const struct pizza*)b;
|
||||
|
||||
if (pizza_a->price < pizza_b->price) {
|
||||
return -1;
|
||||
} else if (pizza_a->price > pizza_b->price) {
|
||||
return 1;
|
||||
} else {
|
||||
return strcmp(pizza_a->name, pizza_b->name);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
struct pizza menu[POCET_JEDAL];
|
||||
memset(menu, 0, sizeof(struct pizza) * POCET_JEDAL);
|
||||
int counter = 0;
|
||||
|
||||
struct pizza item;
|
||||
|
||||
while (read_pizza(&item)) {
|
||||
strcpy(menu[counter].name, item.name);
|
||||
menu[counter].price = item.price;
|
||||
counter += 1;
|
||||
|
||||
if (counter >= POCET_JEDAL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
qsort(menu, counter, sizeof(struct pizza), compare_pizza);
|
||||
|
||||
for (int c = 0; c < counter; c++) {
|
||||
printf("%s\n", menu[c].name);
|
||||
printf("%.6f\n", menu[c].price);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user