test
This commit is contained in:
parent
025162d3e0
commit
c8aacba01c
@ -0,0 +1,64 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAX_STUDENTS 20
|
||||
|
||||
int main() {
|
||||
int maxStudents;
|
||||
printf("Zadajte maximálny počet študentov na prijatie: ");
|
||||
scanf("%d", &maxStudents);
|
||||
|
||||
if (maxStudents <= 0) {
|
||||
printf("Nespravny vstup\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
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("\nPrijati studenti:\n");
|
||||
for (int i = 0; i < maxStudents && i < numStudents; i++) {
|
||||
printf("%s\n", names[i]);
|
||||
}
|
||||
|
||||
if (numStudents > maxStudents) {
|
||||
printf("\nNeprijati studenti:\n");
|
||||
for (int i = maxStudents; i < numStudents; i++) {
|
||||
printf("%s\n", names[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user