45 lines
1.2 KiB
C
45 lines
1.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
int compare(const void *a, const void *b) {
|
|
return strcmp(*(const char **)a, *(const char **)b);
|
|
}
|
|
int main() {
|
|
int max;
|
|
char name[50];
|
|
char **prihlasky = NULL;
|
|
int counter = 0;
|
|
prihlasky = (char **)malloc(max * sizeof(char *));
|
|
if (scanf("%d", &max) != 1 || max <= 0) {
|
|
puts("Nespravny vstup");
|
|
return 0;
|
|
}
|
|
fgets(name, 50, stdin);
|
|
while (fgets(name, 50, stdin) && name[0] != '\n') {
|
|
int checker = 0;
|
|
for(int i = 0;i < counter;i++){
|
|
if(strcmp(prihlasky[i], name) == 0)
|
|
checker = 1;
|
|
}
|
|
if(checker == 0){
|
|
prihlasky[counter] = strdup(name);
|
|
counter++;
|
|
}
|
|
}
|
|
if(counter == 0){
|
|
puts("Ziadne prihlasky");
|
|
return 0;
|
|
}
|
|
qsort(prihlasky, counter, sizeof(char *), compare);
|
|
puts("Prijati studenti:");
|
|
for (int i = 0; i < max && i < counter; i++) {
|
|
printf("%s", prihlasky[i]);
|
|
}
|
|
if (counter > max) {
|
|
puts("Neprijati studenti:");
|
|
for (int i = max; i < counter; i++) {
|
|
printf("%s", prihlasky[i]);
|
|
}
|
|
}
|
|
return 0;
|
|
} |