62 lines
1.6 KiB
C
62 lines
1.6 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#define MAX_STUDENTS 1000 // Maximum number of students
|
|
|
|
int main() {
|
|
int num_students, i;
|
|
char names[MAX_STUDENTS][101];
|
|
char name[101];
|
|
|
|
// Read the maximum number of students
|
|
if (scanf("%d", &num_students) != 1) {
|
|
puts("Nespravny vstup");
|
|
return 1;
|
|
}
|
|
if (num_students <= 0 || num_students > MAX_STUDENTS) {
|
|
puts("Nespravny vstup");
|
|
return 1;
|
|
}
|
|
|
|
// Read the list of applications
|
|
for (i = 0; i < MAX_STUDENTS; i++) {
|
|
if (fgets(name, 101, stdin) == NULL || strcmp(name, "\n") == 0) {
|
|
break; // Stop reading when encountering an empty line or EOF
|
|
}
|
|
name[strcspn(name, "\n")] = '\0'; // Remove the trailing newline character
|
|
strcpy(names[i], name); // Add the name to the list
|
|
}
|
|
|
|
if (i == 0) {
|
|
puts("Ziadne prihlasky");
|
|
return 1;
|
|
}
|
|
|
|
// Sort the list of names in alphabetical order
|
|
for (int j = 0; j < i - 1; j++) {
|
|
for (int k = j + 1; k < i; k++) {
|
|
if (strcmp(names[j], names[k]) > 0) {
|
|
char temp[101];
|
|
strcpy(temp, names[j]);
|
|
strcpy(names[j], names[k]);
|
|
strcpy(names[k], temp);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Print the list of accepted students
|
|
puts("Prijati studenti:");
|
|
for (int j = 0; j < num_students && j < i; j++) {
|
|
printf("%s\n", names[j]);
|
|
}
|
|
|
|
// Print the list of rejected students
|
|
if (i > num_students) {
|
|
puts("Neprijati studenti:");
|
|
for (int j = num_students; j < i; j++) {
|
|
printf("%s\n", names[j]);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
} |