73 lines
1.6 KiB
C
73 lines
1.6 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int main() {
|
|
int count;
|
|
char buffer[100];
|
|
char **applications;
|
|
int i, j;
|
|
|
|
if (scanf("%d", &count) != 1 || count <= 0) {
|
|
printf("Nespravny vstup\n");
|
|
return 1;
|
|
}
|
|
|
|
applications = (char **)malloc(count * sizeof(char *));
|
|
if (!applications) {
|
|
printf("Chyba pri alokacii pamate\n");
|
|
return 1;
|
|
}
|
|
|
|
i = 0;
|
|
while (i < count && scanf("%s", buffer) == 1) {
|
|
int found = 0;
|
|
for (j = 0; j < i; j++) {
|
|
if (strcmp(applications[j], buffer) == 0) {
|
|
found = 1;
|
|
break;
|
|
}
|
|
}
|
|
if (!found) {
|
|
applications[i] = strdup(buffer);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
if (i == 0) {
|
|
printf("Ziadne prihlasky\n");
|
|
return 1;
|
|
}
|
|
|
|
// Sort the applications alphabetically
|
|
for (int m = 0; m < i - 1; m++) {
|
|
for (int n = m + 1; n < i; n++) {
|
|
if (strcmp(applications[m], applications[n]) > 0) {
|
|
char *temp = applications[m];
|
|
applications[m] = applications[n];
|
|
applications[n] = temp;
|
|
}
|
|
}
|
|
}
|
|
|
|
printf("Prijati studenti:\n");
|
|
for (j = 0; j < (count < i ? count : i); j++) {
|
|
printf("%s\n", applications[j]);
|
|
}
|
|
|
|
if (count < i) {
|
|
printf("Neprijati studenti:\n");
|
|
for (; j < i; j++) {
|
|
printf("%s\n", applications[j]);
|
|
}
|
|
}
|
|
|
|
// Free allocated memory
|
|
for (j = 0; j < i; j++) {
|
|
free(applications[j]);
|
|
}
|
|
free(applications);
|
|
|
|
return 0;
|
|
}
|