71 lines
1.8 KiB
C
71 lines
1.8 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
// Funkcia na kontrolu abecedného poradia
|
|
int compare(const void *a, const void *b) {
|
|
return strcmp(*(const char **)a, *(const char **)b);
|
|
}
|
|
|
|
int main() {
|
|
int max_students;
|
|
char **applications = NULL;
|
|
char buffer[100];
|
|
int num_applications = 0;
|
|
|
|
// Načítanie počtu študentov na prijatie
|
|
if (scanf("%d", &max_students) != 1 || max_students <= 0) {
|
|
puts("Nespravny vstup");
|
|
return 1;
|
|
}
|
|
|
|
// Dynamická alokácia pamäte pre zoznam prihlášok
|
|
applications = (char **)malloc(max_students * sizeof(char *));
|
|
if (applications == NULL) {
|
|
puts("Chyba alokacie pamate");
|
|
return 1;
|
|
}
|
|
|
|
// Načítanie prihlášok
|
|
while (scanf("%s", buffer) == 1 && buffer[0] != '\0') {
|
|
applications[num_applications] = strdup(buffer);
|
|
if (applications[num_applications] == NULL) {
|
|
puts("Chyba alokacie pamate");
|
|
return 1;
|
|
}
|
|
num_applications++;
|
|
}
|
|
|
|
// Kontrola, či boli načítané nejaké prihlášky
|
|
if (num_applications == 0) {
|
|
puts("Ziadne prihlasky");
|
|
return 1;
|
|
}
|
|
|
|
// Usporiadanie prihlášok podľa abecedy
|
|
qsort(applications, num_applications, sizeof(char *), compare);
|
|
|
|
// Výpis prijatých študentov
|
|
puts("Prijati studenti:");
|
|
int i;
|
|
for (i = 0; i < num_applications && i < max_students; i++) {
|
|
printf("%s\n", applications[i]);
|
|
}
|
|
|
|
// Výpis neprijatých študentov
|
|
if (i < num_applications) {
|
|
puts("Neprijati studenti:");
|
|
for (; i < num_applications; i++) {
|
|
printf("%s\n", applications[i]);
|
|
}
|
|
}
|
|
|
|
// Uvoľnenie pamäte
|
|
for (i = 0; i < num_applications; i++) {
|
|
free(applications[i]);
|
|
}
|
|
free(applications);
|
|
|
|
return 0;
|
|
}
|