diff --git a/du6/program.c b/du6/program.c index 69b35f6..45588ec 100644 --- a/du6/program.c +++ b/du6/program.c @@ -4,15 +4,14 @@ #include struct LIS{ - - +char name[100]; char fname[100]; -char sname[100]; - +int num; }; + char keep(struct LIS*,int); void sort(struct LIS*,int); -void print(struct LIS *,int,int); +void print(struct LIS*,int,int); int main(){ @@ -20,7 +19,7 @@ struct LIS list[100]; int places=0; int k; k=scanf("%d",&places); -if(k!=1 || places<=0){ +if(k!=1 || places<0){ puts("Nespravny vstup"); } else{ @@ -33,16 +32,29 @@ else{ char keep(struct LIS* list,int places){ -int num=places; -int stop; int count=0; -char fn[100]; - for(;stop!=EOF;count++,num--){ - stop=fscanf(stdin,"%s %s",list[count].sname,list[count].fname); +char names[100]; + for(;fgets(names,100,stdin);){ + if(sscanf(names,"%s %s",list[count].fname,list[count].name)==2){ + if(places>=count){ + list[count].num=0; + } + else{ + list[count].num=1; + } + count++; + } + else if(sscanf(names,"%s",list[count].fname)==1){ + if(places>=count){ + list[count].num=2; + } + else{ + list[count].num=3; + } + count++; + } } - count--; return count; - } void sort(struct LIS* list,int count){ @@ -50,11 +62,11 @@ void sort(struct LIS* list,int count){ char *min; int mini; for(int i=0;i0){ - min=list[j].sname; + for(int j=i+1;j<=count;j++){ + if(strcmp(min,list[j].fname)>0){ + min=list[j].fname; mini=j; } } @@ -64,26 +76,47 @@ void sort(struct LIS* list,int count){ } } + void print(struct LIS *list,int count,int places){ - int j=0; - int nado=places; - if(places>count){ - nado=count; - } - if(places>0){ - puts("Prijati studenti:"); - for(;j0){ + if(places>0){ + printf("Prijati studenti:"); + for(int i=0;i<=count;i++){ + if(list[i].num==2){ + printf("%s\n",list[i].fname); + } + if(list[i].num==0){ + 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); + } + } } } - if(count-places>0) - puts("Neprijati studenti:\n"); - for(int i=j;i