75 lines
1.9 KiB
C
75 lines
1.9 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define SIZE 100
|
|
|
|
int compare(const void* arg1, const void* arg2) {
|
|
char* s1 = *((char**)arg1);
|
|
char* s2 = *((char**)arg2);
|
|
return strcmp(s1, s2);
|
|
}
|
|
|
|
int main() {
|
|
char* pole_smernikov[SIZE];
|
|
memset(pole_smernikov, 0, SIZE * sizeof(char*));
|
|
int pocet_mien_v_poli = 0;
|
|
|
|
// Načítanie maximálneho počtu študentov
|
|
int max_students;
|
|
if (scanf("%d\n", &max_students) != 1 || max_students <= 0) {
|
|
puts("Nespravny vstup");
|
|
return 0;
|
|
}
|
|
|
|
char line[SIZE];
|
|
while (fgets(line, SIZE, stdin) != NULL) {
|
|
line[strcspn(line, "\n")] = 0;
|
|
int pocet_znakov = strlen(line) + 1;
|
|
if (pocet_znakov == 1)
|
|
continue;
|
|
|
|
// 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) {
|
|
pole_smernikov[pocet_mien_v_poli] = malloc(pocet_znakov);
|
|
strcpy(pole_smernikov[pocet_mien_v_poli], line);
|
|
pocet_mien_v_poli += 1;
|
|
}
|
|
}
|
|
|
|
if (pocet_mien_v_poli == 0) {
|
|
puts("Ziadne prihlasky");
|
|
return 0;
|
|
}
|
|
|
|
// Triedenie
|
|
qsort(pole_smernikov, pocet_mien_v_poli, sizeof(char*), compare);
|
|
|
|
// Výpis prijatých a neprijatých študentov
|
|
puts("Prijati studenti:");
|
|
for (int i = 0; i < max_students && i < pocet_mien_v_poli; i++) {
|
|
printf("%s\n", pole_smernikov[i]);
|
|
}
|
|
|
|
if (max_students < pocet_mien_v_poli) {
|
|
puts("Neprijati studenti:");
|
|
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;
|
|
}
|