75 lines
1.7 KiB
C
75 lines
1.7 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define MAX_NAME_LENGTH 100
|
|
|
|
int compare(const void *a, const void *b) {
|
|
return strcmp(*(const char **)a, *(const char **)b);
|
|
}
|
|
|
|
int main() {
|
|
int max_students;
|
|
char temp[MAX_NAME_LENGTH];
|
|
char **students;
|
|
int count = 0, unique_count = 0;
|
|
|
|
if (scanf("%d", &max_students) != 1 || max_students <= 0) {
|
|
puts("Nespravny vstup");
|
|
return 1;
|
|
}
|
|
|
|
students = malloc(max_students * sizeof(char *));
|
|
if (students == NULL) {
|
|
puts("Memory allocation failed");
|
|
return 1;
|
|
}
|
|
|
|
while (scanf("%99s", temp) == 1) {
|
|
int is_unique = 1;
|
|
for (int i = 0; i < unique_count; i++) {
|
|
if (strcmp(students[i], temp) == 0) {
|
|
is_unique = 0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (is_unique) {
|
|
students[unique_count] = strdup(temp);
|
|
if (students[unique_count] == NULL) {
|
|
puts("Memory allocation failed");
|
|
for (int i = 0; i < unique_count; i++) {
|
|
free(students[i]);
|
|
}
|
|
free(students);
|
|
return 1;
|
|
}
|
|
unique_count++;
|
|
if (unique_count >= max_students) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (unique_count == 0) {
|
|
puts("Ziadne prihlasky");
|
|
free(students);
|
|
return 1;
|
|
}
|
|
|
|
qsort(students, unique_count, sizeof(char *), compare);
|
|
|
|
puts("Prijati studenti:");
|
|
for (int i = 0; i < unique_count; i++) {
|
|
puts(students[i]);
|
|
}
|
|
|
|
for (int i = 0; i < unique_count; i++) {
|
|
free(students[i]);
|
|
}
|
|
free(students);
|
|
|
|
return 0;
|
|
}
|
|
|