diff --git a/du6/program.c b/du6/program.c new file mode 100644 index 0000000..087dfca --- /dev/null +++ b/du6/program.c @@ -0,0 +1,92 @@ +#include +#include +#include +#include + +#define SIZE 111 +void pr1(); +void pr2(); +void pr3(); +int compare(const void* arg1, const void* arg2){ + char* s1 = *((char**)arg1); + char* s2 = *((char**)arg2); + int r = strcmp(s1,s2); + return r; +} + +int main(){ + bool search; + int nl; + int xox = 0; + char* pole[SIZE]; + memset(pole,0,SIZE*sizeof(char*)); + nl = 0; + scanf("%d", &nl); + while (2==2) + { + int pz; + char st[SIZE]; + memset(st,0,SIZE); + char* r = fgets(st,SIZE,stdin); + pz = 0; + if (r!=NULL){ + pz = strlen(st); + }else{ + break; + } + search = false; + for (int i = 0; i < xox; i++){ + if (memcmp(pole[i],st,pz) == 0){ + search = true; + } + } + search = false; + if(search){ + pole[xox] = calloc(' ',pz + 1); + memcpy(pole[xox],st,pz + 1); + xox ++; + } + search = false; + } + if (nl < 0 || nl == 0){ + pr1(); + return 0; + } + if (xox==1){ + pr2(); + return 0; + } + + qsort(pole,xox,sizeof(char*),compare); + printf("Prijati studenti:"); + int i2=0; + while (i2 <=nl){ + i2++; + if (pole[i2]!=NULL){ + printf("%s",pole[i2]); + } + } + if (nl+1 < xox){ + pr3(); + } + int i3; + for (i3=nl+1; i3 < xox; i3++){ + if (pole[i3]!=NULL) + { + printf("%s",pole[i3]); + } + } + int i4; + for (i4 = 0; i4 < xox; i4++){ + free(pole[i4]); + } +} +void pr1(){ + printf("Nespravny vstup\n"); +} +void pr2(){ + printf("Ziadne prihlasky\n"); +} +void pr3(){ + printf("Neprijati studenti:\n"); +} \ No newline at end of file