#include #include #include #include struct LIS{ char name[100]; char fname[100]; int num; }; char keep(struct LIS*,int); void sort(struct LIS*,int); void print(struct LIS*,int,int); int main(){ struct LIS list[100]; int places=0; int k; k=scanf("%d",&places); if(k!=1 || places<0){ puts("Nespravny vstup"); } else{ int count=keep(list,places); sort(list,count); print(list,count,places); } return 0; } char keep(struct LIS* list,int places){ int count=0; char names[100]; for(;fgets(names,100,stdin);){ if(names[0]=='\n') continue; if(sscanf(names,"%s %s",list[count].fname,list[count].name)==2){ count++; if(places>=count){ list[count-1].num=0; } else{ list[count-1].num=1; } } else if(sscanf(names,"%s",list[count].fname)==1){ count++; if(places>=count){ list[count-1].num=2; } else{ list[count-1].num=3; } } } return count; } void sort(struct LIS* list,int count){ struct LIS ilusion; char *min; int mini; for(int i=0;i<=count-1;i++){ min=list[i].fname; mini=i; for(int j=i+1;j<=count;j++){ if(strcmp(min,list[j].fname)>0){ min=list[j].fname; mini=j; } } ilusion=list[i]; list[i]=list[mini]; list[mini]=ilusion; } } void print(struct LIS *list,int count,int places){ if(count>0){ if(places>0){ printf("Prijati studenti:\n"); int i=1; if(count==1){ i=0; count--; } for(i;i<=count;i++){ if(list[i].num==2 && list[i].fname[0]!='\n'){ printf("%s\n",list[i].fname); } if(list[i].num==0 && list[i].fname[0]!='\n'){ printf("%s %s\n",list[i].fname,list[i].name); } } } if(count-places>0){ printf("Neprijati studenti:\n"); for(int i=0;i<=count;i++){ if(list[i].num==3){ printf("%s\n",list[i].fname); } if(list[i].num==1){ printf("%s %s\n",list[i].fname,list[i].name); } } } } else{ puts("Ziadne prihlasky"); } }