2020-04-13 21:49:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2020-04-16 00:16:00 +00:00
|
|
|
struct LIS{
|
2020-04-16 13:16:09 +00:00
|
|
|
char name[100];
|
2020-04-16 00:16:00 +00:00
|
|
|
char fname[100];
|
2020-04-16 13:16:09 +00:00
|
|
|
int num;
|
2020-04-16 00:16:00 +00:00
|
|
|
};
|
2020-04-16 13:16:09 +00:00
|
|
|
|
2020-04-16 00:16:00 +00:00
|
|
|
char keep(struct LIS*,int);
|
|
|
|
void sort(struct LIS*,int);
|
2020-04-16 13:16:09 +00:00
|
|
|
void print(struct LIS*,int,int);
|
2020-04-13 21:49:38 +00:00
|
|
|
|
2020-04-16 00:16:00 +00:00
|
|
|
int main(){
|
|
|
|
|
|
|
|
struct LIS list[100];
|
|
|
|
int places=0;
|
|
|
|
int k;
|
|
|
|
k=scanf("%d",&places);
|
2020-04-16 13:16:09 +00:00
|
|
|
if(k!=1 || places<0){
|
2020-04-16 00:16:00 +00:00
|
|
|
puts("Nespravny vstup");
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
int count=keep(list,places);
|
|
|
|
sort(list,count);
|
|
|
|
print(list,count,places);
|
|
|
|
}
|
2020-04-13 21:49:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 00:16:00 +00:00
|
|
|
char keep(struct LIS* list,int places){
|
|
|
|
int count=0;
|
2020-04-16 13:16:09 +00:00
|
|
|
char names[100];
|
2020-04-16 14:22:54 +00:00
|
|
|
for(;fgets(names,100,stdin);){
|
2020-04-16 15:18:48 +00:00
|
|
|
if(names[0]=='\n'){
|
|
|
|
list[count].num=-1;
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-16 13:16:09 +00:00
|
|
|
if(sscanf(names,"%s %s",list[count].fname,list[count].name)==2){
|
2020-04-16 14:22:54 +00:00
|
|
|
count++;
|
2020-04-16 13:16:09 +00:00
|
|
|
if(places>=count){
|
2020-04-16 14:22:54 +00:00
|
|
|
list[count-1].num=0;
|
2020-04-16 13:16:09 +00:00
|
|
|
}
|
|
|
|
else{
|
2020-04-16 14:22:54 +00:00
|
|
|
list[count-1].num=1;
|
2020-04-16 13:16:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(sscanf(names,"%s",list[count].fname)==1){
|
2020-04-16 14:22:54 +00:00
|
|
|
count++;
|
2020-04-16 13:16:09 +00:00
|
|
|
if(places>=count){
|
2020-04-16 14:22:54 +00:00
|
|
|
list[count-1].num=2;
|
2020-04-16 13:16:09 +00:00
|
|
|
}
|
|
|
|
else{
|
2020-04-16 14:22:54 +00:00
|
|
|
list[count-1].num=3;
|
2020-04-16 13:16:09 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-16 00:16:00 +00:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sort(struct LIS* list,int count){
|
|
|
|
struct LIS ilusion;
|
|
|
|
char *min;
|
|
|
|
int mini;
|
2020-04-16 15:09:19 +00:00
|
|
|
for(int i=0;i<=count-1;i++){
|
2020-04-16 13:16:09 +00:00
|
|
|
min=list[i].fname;
|
2020-04-16 00:16:00 +00:00
|
|
|
mini=i;
|
2020-04-16 13:16:09 +00:00
|
|
|
for(int j=i+1;j<=count;j++){
|
2020-04-16 15:47:38 +00:00
|
|
|
if(strcmp(min,list[j].fname)==0 && strcmp(list[mini].name,list[j].name)<0){
|
2020-04-16 15:30:46 +00:00
|
|
|
ilusion=list[i];
|
|
|
|
list[i]=list[mini];
|
2020-04-16 15:43:37 +00:00
|
|
|
list[mini]=ilusion;
|
2020-04-16 15:51:03 +00:00
|
|
|
}
|
|
|
|
if(strcmp(min,list[j].fname)>0){
|
|
|
|
min=list[j].fname;
|
|
|
|
mini=j;
|
2020-04-16 15:43:37 +00:00
|
|
|
}
|
2020-04-16 00:16:00 +00:00
|
|
|
}
|
|
|
|
ilusion=list[i];
|
|
|
|
list[i]=list[mini];
|
|
|
|
list[mini]=ilusion;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-04-16 13:16:09 +00:00
|
|
|
|
2020-04-16 00:16:00 +00:00
|
|
|
void print(struct LIS *list,int count,int places){
|
2020-04-16 13:31:07 +00:00
|
|
|
if(count>0){
|
2020-04-16 13:16:09 +00:00
|
|
|
if(places>0){
|
2020-04-16 13:51:03 +00:00
|
|
|
printf("Prijati studenti:\n");
|
2020-04-16 14:52:03 +00:00
|
|
|
int i=1;
|
|
|
|
for(i;i<=count;i++){
|
|
|
|
if(list[i].num==2 && list[i].fname[0]!='\n'){
|
2020-04-16 13:16:09 +00:00
|
|
|
printf("%s\n",list[i].fname);
|
|
|
|
}
|
2020-04-16 14:52:03 +00:00
|
|
|
if(list[i].num==0 && list[i].fname[0]!='\n'){
|
2020-04-16 13:16:09 +00:00
|
|
|
printf("%s %s\n",list[i].fname,list[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(count-places>0){
|
|
|
|
printf("Neprijati studenti:\n");
|
2020-04-16 14:52:03 +00:00
|
|
|
for(int i=0;i<=count;i++){
|
2020-04-16 13:16:09 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2020-04-16 00:16:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-16 13:16:09 +00:00
|
|
|
else{
|
|
|
|
puts("Ziadne prihlasky");
|
2020-04-16 00:16:00 +00:00
|
|
|
}
|
2020-04-16 15:51:03 +00:00
|
|
|
}
|