From 924e6cea5bbdde206cd751088ad2f6fa2baa6b44 Mon Sep 17 00:00:00 2001 From: Peter Petrek Date: Thu, 14 Oct 2021 23:21:36 +0200 Subject: [PATCH] test --- cv2/Makefile | 11 +++++++++ cv2/program | Bin 0 -> 6313 bytes cv2/program.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 cv2/Makefile create mode 100755 cv2/program create mode 100644 cv2/program.c diff --git a/cv2/Makefile b/cv2/Makefile new file mode 100644 index 0000000..f78f641 --- /dev/null +++ b/cv2/Makefile @@ -0,0 +1,11 @@ +# variables +CC=gcc +CFLAGS=-std=c11 -Wall -Werror +LDLIBS=-lm +OUTPUT=$@ + +# targets +%: %.c + $(CC) $(CFLAGS) $@.c $(LDLIBS) -o $(OUTPUT) + + diff --git a/cv2/program b/cv2/program new file mode 100755 index 0000000000000000000000000000000000000000..1830a60762e0d17c41953adc7664cf1919f86ef7 GIT binary patch literal 6313 zcmb7I4{(&l72of2fdk_iFt$N5dQ%Spha7+9m}%v7lbZ==Jy8y-mJE z?X)lRvisZj_Pw{eZ};2VAJsQ3H4H;&a)=^9G`z>@szwE*#Vu3(dGmfQ3hPS8*=ciz+}p3n=FZa!NXJF56u3eRLN!A0m#7LL5Dgp{Zj5g zF#`P&$jCWhGUfC^UJm``@J+4*CTrP)?_0qEmkr{rgm0m;jnL%SmaW+!`!Y`U@qp>O49vNq{DJSyJ%9AltItIa^?&m3Rj_j6stJm1i_SN%`{=@DC^8XD8sU2#)LU3M+A#tLdjHGa}L?V^2!~~YIM52_jMADYCM867_ zNGuOaB;@+cHP_(ZVR(1%8($NmGc%IU=R10=;=v>uGpAged+BzR@{2|gL4KA%e>Uc4 zF@i9wLj&lVpT$VRlnwPu%!tAq&QOoUj4WJEd{kma81@h!l9-W(=MZ;G%!tFBwV_=S zGxG3a;x^y~A8g6Kn|W{e!NzsrqsX0b4gNi}F?_AV=^A_k3OBmPQD=p>*WPe^KFn2e zHZ!?Nk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E*y(XKye=^1eLgzOCIZR?mj^7R>dSgNg5#W-yg7!-05^Z<{N| zJxYGznQ^?)(Rtv^si(_v3ZXdWw=k70ZD#m!%pLCdg(mrI`DL%C@}<*mh?x^e^5qo| Rv3gPYLaTFc{QIno=0CWW7a0Hm literal 0 HcmV?d00001 diff --git a/cv2/program.c b/cv2/program.c new file mode 100644 index 0000000..8cb81ff --- /dev/null +++ b/cv2/program.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include +#include + +#define velkost strlen +#define size 100 + +struct jedlo { + char name[size]; + float price; +}; + +int compare(const void* p1,const void*p2); + +int main() { + + struct jedlo databaza[size]; + char input[100]= {0}; + float price = 0; + int counter = 0; + int helper = 2; + int counter2 = 0; + int yes = 0; + + while(fgets(input, sizeof(input), stdin) && strcmp( input, "\n" ) != 0 ){ + if(helper %2 == 0){ + strcpy(databaza[counter].name, input); + yes++; + } + else{ + price = strtof(input, NULL); + databaza[counter].price = price; + yes++; + } + if(yes == 2){ + counter++; + yes = 0; + } + counter2++; + helper++; + } + + counter2 = (counter2 / 2) - 1; + qsort(databaza, counter2,sizeof(struct jedlo),compare); + + while(counter2 >= 0){ + printf("%s", databaza[counter2].name); + printf("%f\n", databaza[counter2].price); + counter2--; + } +} + +int compare(const void* p1,const void*p2){ + struct jedlo* s1=(struct jedlo*)p1; + struct jedlo* s2=(struct jedlo*)p2; + + if(s1->price == s2->price){ + return 0; + } + else if(s1->price < s2->price){ + return 1; + } + return -1; +} \ No newline at end of file