93 lines
2.4 KiB
C
93 lines
2.4 KiB
C
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <stdbool.h>
|
||
|
|
||
|
#define ROZMER 100
|
||
|
int compare(const void* a1, const void* a2){//na triedenie poľa
|
||
|
char* string1 = *((char**)a1);
|
||
|
char* string2 = *((char**)a2);
|
||
|
int r = strcmp(string1,string2);
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
int printStatus(int pocet_mien_v_poli,int number_list){
|
||
|
if (number_list < 0 || number_list == 0)
|
||
|
{
|
||
|
printf("Nespravny vstup\n");
|
||
|
return 0;
|
||
|
}
|
||
|
if (pocet_mien_v_poli==1)
|
||
|
{
|
||
|
printf("Ziadne prihlasky\n");
|
||
|
return 0;
|
||
|
}
|
||
|
return 1;
|
||
|
}
|
||
|
void printAllStudents(int pocet_mien_v_poli, int number_list, char* pole_smernikov[ROZMER]){
|
||
|
for (size_t i = 0; i <=number_list ; i++)
|
||
|
{
|
||
|
if (pole_smernikov[i]!=NULL)
|
||
|
{
|
||
|
printf("%s",pole_smernikov[i]);
|
||
|
}
|
||
|
}
|
||
|
if (number_list+1 < pocet_mien_v_poli)
|
||
|
{
|
||
|
printf("Neprijati studenti:\n");
|
||
|
}
|
||
|
for (size_t i = number_list+1; i < pocet_mien_v_poli ; i++)
|
||
|
{
|
||
|
if (pole_smernikov[i]!=NULL)
|
||
|
{
|
||
|
printf("%s",pole_smernikov[i]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main(){
|
||
|
int pocet_mien_v_poli = 0;
|
||
|
int number_list = 0;
|
||
|
char* pole_smernikov[ROZMER];
|
||
|
memset(pole_smernikov,0,ROZMER*sizeof(char*));
|
||
|
scanf("%d", &number_list);
|
||
|
|
||
|
// prečítať všetkých študentov z terminálu
|
||
|
while (true)
|
||
|
{
|
||
|
char line[ROZMER];
|
||
|
memset(line,0,ROZMER);
|
||
|
char* r = fgets(line,ROZMER,stdin);
|
||
|
int pocet_znakov = 0;
|
||
|
if (r!=NULL){
|
||
|
pocet_znakov = strlen(line);
|
||
|
}else{
|
||
|
break;
|
||
|
}
|
||
|
bool find = false;
|
||
|
for (int i = 0; i < pocet_mien_v_poli; i++){
|
||
|
if (memcmp(pole_smernikov[i],line,pocet_znakov) == 0){
|
||
|
find = true;
|
||
|
}
|
||
|
}
|
||
|
if(find == false){
|
||
|
pole_smernikov[pocet_mien_v_poli] = calloc(' ',pocet_znakov + 1);
|
||
|
memcpy(pole_smernikov[pocet_mien_v_poli],line,pocet_znakov + 1);
|
||
|
pocet_mien_v_poli ++;
|
||
|
}
|
||
|
find = false;
|
||
|
}
|
||
|
|
||
|
if (printStatus(pocet_mien_v_poli, number_list) == 0){
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
qsort(pole_smernikov,pocet_mien_v_poli,sizeof(char*),compare);//triedi pole pomocou komparátora
|
||
|
|
||
|
printf("Prijati studenti:");
|
||
|
printAllStudents(pocet_mien_v_poli,number_list,pole_smernikov);
|
||
|
|
||
|
for (int i = 0; i < pocet_mien_v_poli; i++){
|
||
|
free(pole_smernikov[i]);
|
||
|
}
|
||
|
}
|