2024-04-22 12:01:17 +00:00
|
|
|
#include <stdio.h>
|
2024-04-22 17:15:04 +00:00
|
|
|
#include <stdlib.h>
|
2024-04-25 15:29:10 +00:00
|
|
|
#include <string.h>
|
2024-04-22 12:01:17 +00:00
|
|
|
|
2024-04-25 15:29:10 +00:00
|
|
|
typedef struct Student {
|
|
|
|
char name[100];
|
|
|
|
int applied;
|
|
|
|
} Student;
|
2024-04-22 12:01:17 +00:00
|
|
|
|
2024-04-25 15:29:10 +00:00
|
|
|
int cmpfunc(const void *a, const void *b) {
|
|
|
|
Student *student1 = (Student *)a;
|
|
|
|
Student *student2 = (Student *)b;
|
|
|
|
return strcmp(student1->name, student2->name);
|
2024-04-22 17:15:04 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 12:01:17 +00:00
|
|
|
int main() {
|
2024-04-25 15:29:10 +00:00
|
|
|
int max_students, num_students;
|
|
|
|
char name[100];
|
|
|
|
Student students[1000];
|
|
|
|
int students_accepted = 0;
|
|
|
|
int i, j;
|
2024-04-22 12:06:40 +00:00
|
|
|
|
2024-04-25 15:29:10 +00:00
|
|
|
if (scanf("%d", &max_students) != 1 || max_students <= 0) {
|
|
|
|
puts("Nespravny vstup");
|
2024-04-22 12:06:40 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2024-04-22 12:01:17 +00:00
|
|
|
|
2024-04-25 15:29:10 +00:00
|
|
|
if (scanf("%d", &num_students) != 1 || num_students <= 0) {
|
|
|
|
puts("Nespravny vstup");
|
|
|
|
return 1;
|
|
|
|
}
|
2024-04-22 16:31:59 +00:00
|
|
|
|
2024-04-25 15:29:10 +00:00
|
|
|
if (num_students > max_students) {
|
|
|
|
num_students = max_students;
|
|
|
|
}
|
2024-04-22 12:01:17 +00:00
|
|
|
|
2024-04-25 15:29:10 +00:00
|
|
|
for (i = 0; i < num_students; i++) {
|
|
|
|
if (scanf("%s", name) != 1) {
|
|
|
|
puts("Ziadne prihlasky");
|
|
|
|
return 1;
|
|
|
|
}
|
2024-04-22 17:19:03 +00:00
|
|
|
|
2024-04-25 15:29:10 +00:00
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
if (strcmp(students[j].name, name) == 0) {
|
2024-04-22 12:01:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-25 15:29:10 +00:00
|
|
|
if (j == i) {
|
|
|
|
strcpy(students[i].name, name);
|
|
|
|
students[i].applied = 1;
|
2024-04-22 12:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-25 15:29:10 +00:00
|
|
|
qsort(students, i, sizeof(Student), cmpfunc);
|
2024-04-22 17:19:03 +00:00
|
|
|
|
2024-04-25 15:29:10 +00:00
|
|
|
printf("Prijati studenti:\n");
|
|
|
|
for (i = 0; i < max_students; i++) {
|
|
|
|
if (students[i].applied == 1) {
|
|
|
|
printf("%s\n", students[i].name);
|
|
|
|
students_accepted++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (students_accepted < num_students) {
|
|
|
|
printf("Neprijati studenti:\n");
|
|
|
|
for (i = 0; i < num_students; i++) {
|
|
|
|
if (students[i].applied == 0) {
|
|
|
|
printf("%s\n", students[i].name);
|
|
|
|
}
|
2024-04-22 12:06:40 +00:00
|
|
|
}
|
2024-04-22 12:01:17 +00:00
|
|
|
}
|
2024-04-22 16:28:15 +00:00
|
|
|
|
2024-04-22 12:01:17 +00:00
|
|
|
return 0;
|
2024-04-25 15:29:10 +00:00
|
|
|
}
|