diff --git a/a3/program.c b/a3/program.c new file mode 100644 index 0000000..3f920d5 --- /dev/null +++ b/a3/program.c @@ -0,0 +1,70 @@ +#include +#include +#include + +#define MAX 1000 +#define LEN 100 + +int cmp(const void *a, const void *b) { + return strcmp((char *)a, (char *)b); +} + +int main() { + int pocet; + + // načítanie počtu študentov + if (scanf("%d", &pocet) != 1 || pocet <= 0) { + puts("Nespravny vstup"); + return 0; + } + + getchar(); + + char mena[MAX][LEN]; + int count = 0; + + + while (fgets(mena[count], LEN, stdin)) { + + if (mena[count][0] == '\n') + break; + + mena[count][strcspn(mena[count], "\n")] = 0; + count++; + + if (count >= MAX) + break; + } + + if (count == 0) { + puts("Ziadne prihlasky"); + return 0; + } + + + qsort(mena, count, LEN, cmp); + + char unikaty[MAX][LEN]; + int ucount = 0; + + for (int i = 0; i < count; i++) { + if (i == 0 || strcmp(mena[i], mena[i - 1]) != 0) { + strcpy(unikaty[ucount++], mena[i]); + } + } + + puts("Prijati studenti:"); + int prijati = (ucount < pocet) ? ucount : pocet; + for (int i = 0; i < prijati; i++) { + puts(unikaty[i]); + } + + if (ucount > pocet) { + puts("Neprijati studenti:"); + for (int i = pocet; i < ucount; i++) { + puts(unikaty[i]); + } + } + + return 0; +} \ No newline at end of file