2021-10-12 17:20:19 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define LINESIZE 100
|
|
|
|
|
|
|
|
struct Pizza {
|
|
|
|
char name[LINESIZE];
|
|
|
|
float prize;
|
|
|
|
};
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
char line[LINESIZE];
|
|
|
|
memset(line, 0, LINESIZE);
|
|
|
|
char name[LINESIZE];
|
|
|
|
struct Pizza jedalny_listok[LINESIZE];
|
|
|
|
memset(jedalny_listok, 0, sizeof(struct Pizza) * LINESIZE);
|
|
|
|
size_t velkost;
|
2021-10-12 18:34:11 +00:00
|
|
|
int a = 0;
|
|
|
|
int i = 0;
|
2021-10-13 11:22:54 +00:00
|
|
|
int c;
|
|
|
|
int d;
|
|
|
|
float pred;
|
2021-10-12 18:34:11 +00:00
|
|
|
float cena;
|
2021-10-13 11:22:54 +00:00
|
|
|
char strpred[LINESIZE];
|
|
|
|
memset(strpred,0,LINESIZE);
|
2021-10-12 17:20:19 +00:00
|
|
|
while (fgets(line, LINESIZE, stdin)) {
|
|
|
|
velkost = strlen(line);
|
|
|
|
if (velkost == 1 && line[velkost - 1] == '\n') {
|
|
|
|
break;
|
|
|
|
}
|
2021-10-12 18:34:11 +00:00
|
|
|
if (i == 0) {
|
|
|
|
strcpy(jedalny_listok[a].name, line);
|
2021-10-12 17:20:19 +00:00
|
|
|
|
2021-10-12 18:34:11 +00:00
|
|
|
i++;
|
2021-10-14 15:18:58 +00:00
|
|
|
// a++;
|
2021-10-12 18:34:11 +00:00
|
|
|
}
|
|
|
|
else if (i == 1){
|
|
|
|
cena = atof(line);
|
|
|
|
jedalny_listok[a].prize = cena;
|
2021-10-12 17:20:19 +00:00
|
|
|
|
2021-10-12 18:34:11 +00:00
|
|
|
i--;
|
|
|
|
a++;
|
2021-10-14 15:18:58 +00:00
|
|
|
|
2021-10-12 18:34:11 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-13 11:22:54 +00:00
|
|
|
|
2021-10-14 15:19:56 +00:00
|
|
|
//printf("nacitane pizze v liste: %d\n", a);
|
2021-10-14 15:18:58 +00:00
|
|
|
|
|
|
|
// a = a / 2;
|
2021-10-14 08:09:30 +00:00
|
|
|
//printf("%d", a);
|
2021-10-14 15:18:58 +00:00
|
|
|
for (c = 0; c < a-1; c++){
|
|
|
|
for (d = 0; d < a - c-1; d++){
|
|
|
|
if(jedalny_listok[d].prize == jedalny_listok[d+1].prize){
|
|
|
|
if(strcmp(jedalny_listok[d].name, jedalny_listok[d+1].name) > 0){
|
|
|
|
struct Pizza tmp;
|
|
|
|
strcpy(tmp.name, jedalny_listok[d].name);
|
|
|
|
tmp.prize = jedalny_listok[d].prize;
|
|
|
|
|
|
|
|
strcpy(jedalny_listok[d].name, jedalny_listok[d+1].name);
|
|
|
|
jedalny_listok[d].prize = jedalny_listok[d+1].prize;
|
|
|
|
|
|
|
|
strcpy(jedalny_listok[d+1].name, tmp.name);
|
|
|
|
jedalny_listok[d+1].prize = tmp.prize;
|
2021-10-14 08:08:53 +00:00
|
|
|
|
2021-10-13 11:42:33 +00:00
|
|
|
}
|
2021-10-13 11:22:54 +00:00
|
|
|
}
|
2021-10-14 15:18:58 +00:00
|
|
|
|
|
|
|
else if(jedalny_listok[d].prize > jedalny_listok[d+1].prize){
|
|
|
|
struct Pizza tmp;
|
|
|
|
strcpy(tmp.name, jedalny_listok[d].name);
|
|
|
|
tmp.prize = jedalny_listok[d].prize;
|
|
|
|
|
|
|
|
strcpy(jedalny_listok[d].name, jedalny_listok[d+1].name);
|
|
|
|
jedalny_listok[d].prize = jedalny_listok[d+1].prize;
|
|
|
|
|
|
|
|
strcpy(jedalny_listok[d+1].name, tmp.name);
|
|
|
|
jedalny_listok[d+1].prize = tmp.prize;
|
|
|
|
}
|
2021-10-13 11:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-14 15:18:58 +00:00
|
|
|
for( int x = 0; x < a; x++){
|
2021-10-14 15:19:56 +00:00
|
|
|
printf("%s", jedalny_listok[x].name);
|
|
|
|
printf("%f\n", jedalny_listok[x].prize);
|
2021-10-14 15:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-13 11:22:54 +00:00
|
|
|
a = a * 2;
|
2021-10-12 18:34:11 +00:00
|
|
|
for (i = 0; i<a; i++){
|
2021-10-13 11:22:54 +00:00
|
|
|
|
2021-10-12 18:34:11 +00:00
|
|
|
if (i == 0 || i % 2 == 0) {
|
2021-10-14 08:08:53 +00:00
|
|
|
printf("%s", jedalny_listok[i].name);
|
2021-10-12 18:34:11 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("%f\n", jedalny_listok[i].prize);
|
|
|
|
}
|
2021-10-12 17:20:19 +00:00
|
|
|
}
|
2021-10-14 15:18:58 +00:00
|
|
|
**/
|
2021-10-12 17:20:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|