70 lines
1.3 KiB
C
70 lines
1.3 KiB
C
#include<stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define MAX 1000
|
|
#define LEN 100
|
|
|
|
int cmp(const void *a, const void *b) {
|
|
return strcmp((char *)a, (char *)b);
|
|
}
|
|
|
|
int main() {
|
|
int pocet;
|
|
|
|
// načítanie počtu študentov
|
|
if (scanf("%d", &pocet) != 1 || pocet <= 0) {
|
|
puts("Nespravny vstup");
|
|
return 0;
|
|
}
|
|
|
|
getchar();
|
|
|
|
char mena[MAX][LEN];
|
|
int count = 0;
|
|
|
|
|
|
while (fgets(mena[count], LEN, stdin)) {
|
|
|
|
if (mena[count][0] == '\n')
|
|
break;
|
|
|
|
mena[count][strcspn(mena[count], "\n")] = 0;
|
|
count++;
|
|
|
|
if (count >= MAX)
|
|
break;
|
|
}
|
|
|
|
if (count == 0) {
|
|
puts("Ziadne prihlasky");
|
|
return 0;
|
|
}
|
|
|
|
|
|
qsort(mena, count, LEN, cmp);
|
|
|
|
char unikaty[MAX][LEN];
|
|
int ucount = 0;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
if (i == 0 || strcmp(mena[i], mena[i - 1]) != 0) {
|
|
strcpy(unikaty[ucount++], mena[i]);
|
|
}
|
|
}
|
|
|
|
puts("Prijati studenti:");
|
|
int prijati = (ucount < pocet) ? ucount : pocet;
|
|
for (int i = 0; i < prijati; i++) {
|
|
puts(unikaty[i]);
|
|
}
|
|
|
|
if (ucount > pocet) {
|
|
puts("Neprijati studenti:");
|
|
for (int i = pocet; i < ucount; i++) {
|
|
puts(unikaty[i]);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
} |