63 lines
1.3 KiB
C
63 lines
1.3 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#define MAX_STUDENTS 20
|
|
|
|
int main() {
|
|
int maxStudents;
|
|
scanf("%d", &maxStudents);
|
|
|
|
if (maxStudents <= 0) {
|
|
printf("Nespravny vstup\n");
|
|
return 0;
|
|
}
|
|
|
|
char names[MAX_STUDENTS][50];
|
|
int numStudents = 0;
|
|
char line[100];
|
|
|
|
fgets(line, sizeof(line), stdin);
|
|
|
|
while (fgets(line, sizeof(line), stdin) != NULL && line[0] != '\n') {
|
|
line[strcspn(line, "\n")] = '\0';
|
|
strcpy(names[numStudents], line);
|
|
numStudents++;
|
|
|
|
if (numStudents >= MAX_STUDENTS) {
|
|
printf("Príliš veľa študentov. Zvážte navýšenie MAX_STUDENTS.\n");
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
if (numStudents == 0) {
|
|
printf("Ziadne prihlášky\n");
|
|
return 1;
|
|
}
|
|
|
|
for (int i = 0; i < numStudents; i++) {
|
|
for (int j = i + 1; j < numStudents; j++) {
|
|
if (strcmp(names[i], names[j]) == 0) {
|
|
memmove(&names[j], &names[j + 1], (numStudents - j - 1) * sizeof(names[0]));
|
|
numStudents--;
|
|
j--;
|
|
}
|
|
}
|
|
}
|
|
|
|
qsort(names, numStudents, sizeof(names[0]), strcmp);
|
|
|
|
printf("Prijati studenti:\n");
|
|
for (int i = 0; i < maxStudents && i < numStudents; i++) {
|
|
printf("%s\n", names[i]);
|
|
}
|
|
|
|
if (numStudents > maxStudents) {
|
|
printf("Neprijati studenti:\n");
|
|
for (int i = maxStudents; i < numStudents; i++) {
|
|
printf("%s\n", names[i]);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
} |