102 lines
2.6 KiB
C
102 lines
2.6 KiB
C
#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;
|
|
int a = 0;
|
|
int i = 0;
|
|
int c;
|
|
int d;
|
|
float pred;
|
|
float cena;
|
|
char strpred[LINESIZE];
|
|
memset(strpred,0,LINESIZE);
|
|
while (fgets(line, LINESIZE, stdin)) {
|
|
velkost = strlen(line);
|
|
if (velkost == 1 && line[velkost - 1] == '\n') {
|
|
break;
|
|
}
|
|
if (i == 0) {
|
|
strcpy(jedalny_listok[a].name, line);
|
|
|
|
i++;
|
|
// a++;
|
|
}
|
|
else if (i == 1){
|
|
cena = atof(line);
|
|
jedalny_listok[a].prize = cena;
|
|
|
|
i--;
|
|
a++;
|
|
|
|
}
|
|
}
|
|
|
|
//printf("nacitane pizze v liste: %d\n", a);
|
|
|
|
// a = a / 2;
|
|
//printf("%d", a);
|
|
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;
|
|
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
for( int x = 0; x < a; x++){
|
|
printf("%s", jedalny_listok[x].name);
|
|
printf("%f\n", jedalny_listok[x].prize);
|
|
}
|
|
|
|
/**
|
|
a = a * 2;
|
|
for (i = 0; i<a; i++){
|
|
|
|
if (i == 0 || i % 2 == 0) {
|
|
printf("%s", jedalny_listok[i].name);
|
|
}
|
|
else {
|
|
printf("%f\n", jedalny_listok[i].prize);
|
|
}
|
|
}
|
|
**/
|
|
return 0;
|
|
} |