From 7f4966f6fe3a5015a49d660228bb3b526d3abdde Mon Sep 17 00:00:00 2001 From: Pavlo Tverdyi Date: Thu, 16 Apr 2020 19:09:03 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20'du6/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du6/program.c | 92 ++++++++++++++++----------------------------------- 1 file changed, 29 insertions(+), 63 deletions(-) diff --git a/du6/program.c b/du6/program.c index 1a3858d..f66c470 100644 --- a/du6/program.c +++ b/du6/program.c @@ -4,7 +4,6 @@ #include struct LIS{ -char name[100]; char fname[100]; int num; }; @@ -34,53 +33,25 @@ else{ char keep(struct LIS* list,int places){ int count=0; char names[100]; - for(;fgets(names,100,stdin);){ - if(names[0]=='\n'){ - list[count].num=-1; - continue; + for(;fgets(list[count].fname,100,stdin);count++){ + if(list[count].fname[0]=='\n'){ + list[count].num=-1; +// printf("skip"); + } + if(list[count].fname[0]!='\n'){ + list[count].num=0; } - 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; - if(list[0].num==0 || list[0].num==1) + +struct LIS ilusion; +char *min; +char *mickro; +int mini; for(int i=0;i<=count-1;i++){ - min=list[i].name; - mini=i; - for(int j=i+1;j<=count;j++){ - if(strcmp(min,list[j].name)>0){ - min=list[j].name; - mini=j; - } - } - ilusion=list[i]; - list[i]=list[mini]; - list[mini]=ilusion; - } - //// - for(int i=0;i<=count-1;i++){ min=list[i].fname; mini=i; for(int j=i+1;j<=count;j++){ @@ -89,41 +60,36 @@ void sort(struct LIS* list,int count){ mini=j; } } - ilusion=list[i]; - list[i]=list[mini]; - list[mini]=ilusion; + 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; - 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); + int k=0; + puts("Prijati studenti:"); + for(int i=0;k!=places+1;i++){ + if(list[i].num==0){ + puts(list[i].fname); + k++; } } } 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); + int k=0; + puts("Neprijati studenti:"); + for(int i=places+1;i