73 lines
2.1 KiB
C
73 lines
2.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define SIZE 100
|
|
|
|
int compare(const void* arg1, const void* arg2) {
|
|
const char* s1 = *((const char**)arg1);
|
|
const char* s2 = *((const char**)arg2);
|
|
return strcmp(s1, s2);
|
|
}
|
|
|
|
int main() {
|
|
char* pole_smernikov[SIZE] = {NULL}; // Inicializujeme všetky smerníky na NULL
|
|
int pocet_mien_v_poli = 0;
|
|
|
|
char line[SIZE];
|
|
while (fgets(line, SIZE, stdin) != NULL) {
|
|
int pocet_znakov = strlen(line);
|
|
if (pocet_znakov == 1 && line[0] == '\n') // Skončiť na prázdnom riadku
|
|
break;
|
|
|
|
// Odstrániť koniec riadka
|
|
if (line[pocet_znakov - 1] == '\n')
|
|
line[--pocet_znakov] = '\0';
|
|
|
|
// Kontrola duplicít
|
|
int found = 0;
|
|
for (int i = 0; i < pocet_mien_v_poli; i++) {
|
|
if (strcmp(pole_smernikov[i], line) == 0) {
|
|
found = 1;
|
|
break;
|
|
}
|
|
}
|
|
if (!found && pocet_mien_v_poli < SIZE) {
|
|
pole_smernikov[pocet_mien_v_poli] = malloc(pocet_znakov + 1);
|
|
if (pole_smernikov[pocet_mien_v_poli] == NULL) {
|
|
fprintf(stderr, "Chyba pri alokácii pamäte\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
strcpy(pole_smernikov[pocet_mien_v_poli], line);
|
|
pocet_mien_v_poli += 1;
|
|
}
|
|
}
|
|
|
|
// Triedenie
|
|
qsort(pole_smernikov, pocet_mien_v_poli, sizeof(char*), compare);
|
|
|
|
// Výpis prijatých a neprijatých študentov
|
|
int max_students;
|
|
if (scanf("%d", &max_students) != 1) { // Kontrola úspešnosti načítania
|
|
fprintf(stderr, "Chyba pri načítaní počtu študentov\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
printf("Prijati studenti:\n");
|
|
for (int i = 0; i < max_students && i < pocet_mien_v_poli; i++) {
|
|
printf("%s\n", pole_smernikov[i]);
|
|
}
|
|
|
|
printf("Neprijati studenti:\n");
|
|
for (int i = max_students; i < pocet_mien_v_poli; i++) {
|
|
printf("%s\n", pole_smernikov[i]);
|
|
}
|
|
|
|
// Uvoľnenie pamäte
|
|
for (int i = 0; i < pocet_mien_v_poli; i++) {
|
|
free(pole_smernikov[i]);
|
|
}
|
|
|
|
return 0;
|
|
}
|