Initialization
This commit is contained in:
parent
ebd2341fdf
commit
7576de98d7
@ -1,63 +1,49 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define MAX_STUDENTS 100
|
#define MAX_LENGTH 100 // Maximálna dĺžka mena študenta
|
||||||
#define NAME_SIZE 50
|
#define MAX_STUDENTS 100 // Maximálny počet študentov
|
||||||
|
|
||||||
|
int compare(const void *a, const void *b) {
|
||||||
|
return strcmp(*(const char **)a, *(const char **)b);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int max_students, num_accepted = 0, num_students = 0;
|
char prihlasky[MAX_STUDENTS][MAX_LENGTH]; // Pole pre uloženie prihlášok
|
||||||
char names[MAX_STUDENTS][NAME_SIZE];
|
int max_prijati, pocet_prihlasek = 0;
|
||||||
char temp_name[NAME_SIZE];
|
|
||||||
|
|
||||||
scanf("%d", &max_students);
|
// Načítanie maximálneho počtu študentov na prijatie
|
||||||
if (max_students <= 0 || max_students > MAX_STUDENTS) {
|
if (scanf("%d", &max_prijati) != 1 || max_prijati <= 0) {
|
||||||
printf("Nespravny vstup\n");
|
printf("Nespravny vstup\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(names, 0, sizeof(names));
|
// Načítanie zoznamu prihlášok
|
||||||
|
while (scanf("%s", prihlasky[pocet_prihlasek]) == 1) {
|
||||||
while (fgets(temp_name, sizeof(temp_name), stdin)!= NULL && num_accepted < max_students) {
|
pocet_prihlasek++;
|
||||||
temp_name[strcspn(temp_name, "\n")] = '\0';
|
|
||||||
|
|
||||||
int i, found = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < num_accepted; i++) {
|
|
||||||
if (strcmp(names[i], temp_name) == 0) {
|
|
||||||
found = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
// Kontrola, či neboli načítané žiadne prihlášky
|
||||||
strcpy(names[num_accepted], temp_name);
|
if (pocet_prihlasek == 0) {
|
||||||
num_accepted++;
|
printf("Ziadne prihlasky\n");
|
||||||
}
|
return 1;
|
||||||
num_students++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_accepted == 0) {
|
// Zoradenie zoznamu prihlášok podľa abecedy
|
||||||
printf("Ziadne prihlasky");
|
qsort(prihlasky, pocet_prihlasek, sizeof(prihlasky[0]), compare);
|
||||||
} else {
|
|
||||||
printf("Prijati studenti:");
|
|
||||||
for (int i = 0; i < num_accepted; i++) {
|
|
||||||
printf("%s\n", names[i]);
|
|
||||||
}
|
|
||||||
printf("%d1",num_accepted);
|
|
||||||
printf("%d2",num_students);
|
|
||||||
|
|
||||||
if (num_students > num_accepted) {
|
// Výber študentov na prijatie podľa abecedy a maximálneho počtu
|
||||||
printf("Neprijati studenti:");
|
printf("Prijati studenti:\n");
|
||||||
for (int i = 0; i < num_students; i++) {
|
for (int i = 0; i < max_prijati && i < pocet_prihlasek; i++) {
|
||||||
strcpy(temp_name, names[i]);
|
printf("%s\n", prihlasky[i]);
|
||||||
int found = 0;
|
|
||||||
for (int j = 0; j < num_accepted; j++) {
|
|
||||||
if (strcmp(names[j], temp_name) == 0) {
|
|
||||||
found = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Výpis neprijatých študentov
|
||||||
|
if (max_prijati < pocet_prihlasek) {
|
||||||
|
printf("Neprijati studenti:\n");
|
||||||
|
for (int i = max_prijati; i < pocet_prihlasek; i++) {
|
||||||
|
printf("%s\n", prihlasky[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user