55 lines
1.4 KiB
C
55 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
|
|
#define LINESIZE 100
|
|
struct pizza {
|
|
float price;
|
|
char name[LINESIZE];
|
|
};
|
|
|
|
int compare_pizza(const void *a, const void *b) {
|
|
const struct pizza *pizza1 = (const struct pizza *)a;
|
|
const struct pizza *pizza2 = (const struct pizza *)b;
|
|
if (pizza1->price < pizza2->price) return -1;
|
|
if (pizza1->price > pizza2->price) return 1;
|
|
return strcmp(pizza1->name, pizza2->name);
|
|
}
|
|
|
|
int main(){
|
|
struct pizza menu[LINESIZE];
|
|
int count = 0;
|
|
char vstup[LINESIZE];
|
|
while (count < LINESIZE) {
|
|
if (fgets(vstup, LINESIZE, stdin)) {
|
|
vstup[strcspn(vstup, "\n")] = '\0';
|
|
if (strlen(vstup) == 0) {
|
|
break;
|
|
}
|
|
strcpy(menu[count].name, vstup);
|
|
} else {
|
|
break;
|
|
}
|
|
|
|
if (fgets(vstup, LINESIZE, stdin)) {
|
|
vstup[strcspn(vstup, "\n")] = '\0';
|
|
if (strlen(vstup) == 0) {
|
|
break;
|
|
}
|
|
float cislo = strtof(vstup, NULL);
|
|
menu[count].price = cislo;
|
|
} else {
|
|
break;
|
|
}
|
|
count++;
|
|
}
|
|
qsort (menu, count, sizeof(struct pizza), compare_pizza);
|
|
for(int i = 0; i < count;i++){
|
|
if(menu[i].price != 0){
|
|
printf("%s\n", menu[i].name);
|
|
printf("%f\n", menu[i].price);
|
|
}
|
|
}
|
|
return 0;
|
|
} |